From 01de14b2fba23f991622e551e015f014588b14a7 Mon Sep 17 00:00:00 2001 From: Tim Riedl Date: Thu, 29 Aug 2024 12:13:58 +0200 Subject: [PATCH] . --- .../backend/src/helper/customerrors/err_database.go | 12 ++++++++++-- .../helper/customerrors/err_database_not_found.go | 11 +++++++++-- .../err_database_transaction_begin_failed.go | 12 ++++++++++-- .../err_database_transaction_commit_failed.go | 12 ++++++++++-- .../src/helper/customerrors/err_internal_server.go | 8 ++++++-- 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/services/backend/src/helper/customerrors/err_database.go b/services/backend/src/helper/customerrors/err_database.go index 173506e..256b90a 100644 --- a/services/backend/src/helper/customerrors/err_database.go +++ b/services/backend/src/helper/customerrors/err_database.go @@ -26,7 +26,7 @@ type DatabaseError struct { } func NewDatabaseError(err error, userID string, errorContextData string, sqlQuery string, sqlData SqlData) *DatabaseError { - return &DatabaseError{ + model := &DatabaseError{ ID: uuid.New().String(), errorIdentifier: errorconst.ERROR_IDENTIFIER_DATABASE, @@ -41,6 +41,10 @@ func NewDatabaseError(err error, userID string, errorContextData string, sqlQuer error: err, } + + fmt.Printf("🚨 %s\n", model.GetDeveloperMessage()) + + return model } func (e *DatabaseError) Error() string { @@ -53,7 +57,7 @@ func (e *DatabaseError) ErrorType() (errorIdentifier errorconst.ErrorIdentifier) func (e *DatabaseError) HttpError() (int, errorconst.ErrorIdentifier, string) { if debugMode { - errormessage := fmt.Sprintf("[%s] #%s
%s
%s", e.errorIdentifier, e.ID, e.httpUserMessage, e.error.Error()) + errormessage := e.GetDeveloperMessage() return e.httpStatus, e.errorIdentifier, errormessage } return e.httpStatus, e.errorIdentifier, e.httpUserMessage @@ -68,3 +72,7 @@ func (e *DatabaseError) LoggerError() (time.Time, int, errorconst.ErrorIdentifie ) return time.Now(), e.httpStatus, e.errorIdentifier, e.requestingUserID, contextData, e.error.Error() } + +func (e *DatabaseError) GetDeveloperMessage() string { + return fmt.Sprintf("[%s] #%s
%s
%s", e.errorIdentifier, e.ID, e.httpUserMessage, e.error.Error()) +} diff --git a/services/backend/src/helper/customerrors/err_database_not_found.go b/services/backend/src/helper/customerrors/err_database_not_found.go index 39cbf4e..6af0564 100644 --- a/services/backend/src/helper/customerrors/err_database_not_found.go +++ b/services/backend/src/helper/customerrors/err_database_not_found.go @@ -25,7 +25,7 @@ type DatabaseNotFoundError struct { } func NewDatabaseNotFoundError(err error, userID string, sqlQuery string, sqlData SqlData) *DatabaseNotFoundError { - return &DatabaseNotFoundError{ + model := &DatabaseNotFoundError{ ID: uuid.New().String(), errorIdentifier: errorconst.ERROR_IDENTIFIER_DATABASE_NOT_FOUND, @@ -39,6 +39,9 @@ func NewDatabaseNotFoundError(err error, userID string, sqlQuery string, sqlData error: err, } + fmt.Printf("🚨 %s\n", model.GetDeveloperMessage()) + + return model } func (e *DatabaseNotFoundError) Error() string { @@ -51,7 +54,7 @@ func (e *DatabaseNotFoundError) ErrorType() (errorIdentifier errorconst.ErrorIde func (e *DatabaseNotFoundError) HttpError() (int, errorconst.ErrorIdentifier, string) { if debugMode { - errormessage := fmt.Sprintf("[%s] #%s
%s
%s", e.errorIdentifier, e.ID, e.httpUserMessage, e.error.Error()) + errormessage := e.GetDeveloperMessage() return e.httpStatus, e.errorIdentifier, errormessage } return e.httpStatus, e.errorIdentifier, e.httpUserMessage @@ -65,3 +68,7 @@ func (e *DatabaseNotFoundError) LoggerError() (time.Time, int, errorconst.ErrorI ) return time.Now(), e.httpStatus, e.errorIdentifier, e.requestingUserID, contextData, e.error.Error() } + +func (e *DatabaseNotFoundError) GetDeveloperMessage() string { + return fmt.Sprintf("[%s] #%s
%s
%s", e.errorIdentifier, e.ID, e.httpUserMessage, e.error.Error()) +} diff --git a/services/backend/src/helper/customerrors/err_database_transaction_begin_failed.go b/services/backend/src/helper/customerrors/err_database_transaction_begin_failed.go index adc0e7f..3cd97a9 100644 --- a/services/backend/src/helper/customerrors/err_database_transaction_begin_failed.go +++ b/services/backend/src/helper/customerrors/err_database_transaction_begin_failed.go @@ -22,7 +22,7 @@ type DatabaseTransactionBeginError struct { } func NewDatabaseTransactionBeginError(err error, errorContextData string) *DatabaseTransactionBeginError { - return &DatabaseTransactionBeginError{ + model := &DatabaseTransactionBeginError{ ID: uuid.New().String(), errorIdentifier: errorconst.ERROR_IDENTIFIER_DATABASE_TRANSACTION_NOT_STARTED, @@ -33,6 +33,10 @@ func NewDatabaseTransactionBeginError(err error, errorContextData string) *Datab error: err, } + + fmt.Printf("🚨 %s\n", model.GetDeveloperMessage()) + + return model } func (e *DatabaseTransactionBeginError) Error() string { @@ -45,7 +49,7 @@ func (e *DatabaseTransactionBeginError) ErrorType() (errorIdentifier errorconst. func (e *DatabaseTransactionBeginError) HttpError() (int, errorconst.ErrorIdentifier, string) { if debugMode { - errormessage := fmt.Sprintf("[%s] #%s
%s
%s", e.errorIdentifier, e.ID, e.httpUserMessage, e.error.Error()) + errormessage := e.GetDeveloperMessage() return e.httpStatus, e.errorIdentifier, errormessage } return e.httpStatus, e.errorIdentifier, e.httpUserMessage @@ -54,3 +58,7 @@ func (e *DatabaseTransactionBeginError) HttpError() (int, errorconst.ErrorIdenti func (e *DatabaseTransactionBeginError) LoggerError() (time.Time, int, errorconst.ErrorIdentifier, string, string, string) { return time.Now(), e.httpStatus, e.errorIdentifier, "", "", e.error.Error() } + +func (e *DatabaseTransactionBeginError) GetDeveloperMessage() string { + return fmt.Sprintf("[%s] #%s
%s
%s", e.errorIdentifier, e.ID, e.httpUserMessage, e.error.Error()) +} diff --git a/services/backend/src/helper/customerrors/err_database_transaction_commit_failed.go b/services/backend/src/helper/customerrors/err_database_transaction_commit_failed.go index e979db3..c4d75b0 100644 --- a/services/backend/src/helper/customerrors/err_database_transaction_commit_failed.go +++ b/services/backend/src/helper/customerrors/err_database_transaction_commit_failed.go @@ -22,7 +22,7 @@ type DatabaseTransactionCommitError struct { } func NewDatabaseTransactionCommitError(err error, errorContextData string) *DatabaseTransactionCommitError { - return &DatabaseTransactionCommitError{ + model := &DatabaseTransactionCommitError{ ID: uuid.New().String(), errorIdentifier: errorconst.ERROR_IDENTIFIER_DATABASE_TRANSACTION_NOT_STARTED, @@ -33,6 +33,10 @@ func NewDatabaseTransactionCommitError(err error, errorContextData string) *Data error: err, } + + fmt.Printf("🚨 %s\n", model.GetDeveloperMessage()) + + return model } func (e *DatabaseTransactionCommitError) Error() string { @@ -45,7 +49,7 @@ func (e *DatabaseTransactionCommitError) ErrorType() (errorIdentifier errorconst func (e *DatabaseTransactionCommitError) HttpError() (int, errorconst.ErrorIdentifier, string) { if debugMode { - errormessage := fmt.Sprintf("[%s] #%s
%s
%s", e.errorIdentifier, e.ID, e.httpUserMessage, e.error.Error()) + errormessage := e.GetDeveloperMessage() return e.httpStatus, e.errorIdentifier, errormessage } return e.httpStatus, e.errorIdentifier, e.httpUserMessage @@ -54,3 +58,7 @@ func (e *DatabaseTransactionCommitError) HttpError() (int, errorconst.ErrorIdent func (e *DatabaseTransactionCommitError) LoggerError() (time.Time, int, errorconst.ErrorIdentifier, string, string, string) { return time.Now(), e.httpStatus, e.errorIdentifier, "", "", e.error.Error() } + +func (e *DatabaseTransactionCommitError) GetDeveloperMessage() string { + return fmt.Sprintf("[%s] #%s
%s
%s", e.errorIdentifier, e.ID, e.httpUserMessage, e.error.Error()) +} diff --git a/services/backend/src/helper/customerrors/err_internal_server.go b/services/backend/src/helper/customerrors/err_internal_server.go index 401f6ba..dd92728 100644 --- a/services/backend/src/helper/customerrors/err_internal_server.go +++ b/services/backend/src/helper/customerrors/err_internal_server.go @@ -38,7 +38,7 @@ func NewInternalServerError(err error, userID string, errorContextData string) * error: err, } - fmt.Println("🚨") + fmt.Printf("🚨 %s\n", model.GetDeveloperMessage()) return model } @@ -53,7 +53,7 @@ func (e *InternalServerError) ErrorType() (errorIdentifier errorconst.ErrorIdent func (e *InternalServerError) HttpError() (int, errorconst.ErrorIdentifier, string) { if debugMode { - errormessage := fmt.Sprintf("[%s] #%s
%s
%s", e.errorIdentifier, e.ID, e.httpUserMessage, e.error.Error()) + errormessage := e.GetDeveloperMessage() return e.httpStatus, e.errorIdentifier, errormessage } return e.httpStatus, e.errorIdentifier, e.httpUserMessage @@ -62,3 +62,7 @@ func (e *InternalServerError) HttpError() (int, errorconst.ErrorIdentifier, stri func (e *InternalServerError) LoggerError() (time.Time, int, errorconst.ErrorIdentifier, string, string, string) { return time.Now(), e.httpStatus, e.errorIdentifier, e.requestingUserID, e.errorContextData, e.error.Error() } + +func (e *InternalServerError) GetDeveloperMessage() string { + return fmt.Sprintf("[%s] #%s
%s
%s", e.errorIdentifier, e.ID, e.httpUserMessage, e.error.Error()) +}