Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add error for handling internal server error #4

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
)
Loading