Skip to content

Commit

Permalink
feat: add error for handling internal server error
Browse files Browse the repository at this point in the history
  • Loading branch information
sky3742 committed Mar 22, 2024
1 parent 0d3e228 commit 78a8dc8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/api/handlers/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func ErrorsMap() map[error]interface{} {
"internalCode": http.StatusForbidden,
"serviceCode": constants.STATUS_CODE_NOT_AUTHORIZED,
}
errorMap[constants.ERROR_INTERNAL_SERVER] = map[string]interface{}{
"internalCode": http.StatusInternalServerError,
"serviceCode": constants.STATUS_CODE_INTERNAL_SERVER_ERROR,
}

// gorm errors
errorMap[gorm.ErrRecordNotFound] = map[string]interface{}{
Expand Down
3 changes: 3 additions & 0 deletions pkg/utils/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const (
MSG_UNABLE_TO_BIND_BODY string = "error binding body"
MSG_FORBIDDEN string = "forbidden"
MSG_UNKNOWN_DB_PLATFORM string = "unknown database platform"
MSG_INTERNAL_SERVER string = "internal server error"

// output status codes
STATUS_CODE_SERVICE_SUCCESS string = "20001"
Expand Down Expand Up @@ -115,6 +116,7 @@ const (
STATUS_CODE_ID_NOT_FOUND string = "40404"
STATUS_CODE_NOT_ACCEPTABLE_WITHOUT_ACCEPT_HEADER string = "40601"
STATUS_CODE_NOT_ACCEPTABLE_WITHOUT_CONTENT_TYPE_HEADER string = "40602"
STATUS_CODE_INTERNAL_SERVER_ERROR string = "50001"
STATUS_CODE_FAILED_TO_DECODE_VALUE string = "50011"
)

Expand All @@ -129,4 +131,5 @@ var (
ERROR_ACCESS_IDS_NOT_FOUND = errors.New(MSG_SESSION_NOT_FOUND)
ERROR_BINDING_BODY = errors.New(MSG_UNABLE_TO_BIND_BODY)
ERROR_UNKNOWN_DB_PLATFORM = errors.New(MSG_UNKNOWN_DB_PLATFORM)
ERROR_INTERNAL_SERVER = errors.New(MSG_INTERNAL_SERVER)
)

0 comments on commit 78a8dc8

Please sign in to comment.