From 78a8dc8c8a9fdfe79168af4a6cb03c89f8846ced Mon Sep 17 00:00:00 2001 From: Sky Date: Fri, 22 Mar 2024 07:43:37 +0000 Subject: [PATCH] feat: add error for handling internal server error --- pkg/api/handlers/errors/errors.go | 4 ++++ pkg/utils/constants/constants.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/pkg/api/handlers/errors/errors.go b/pkg/api/handlers/errors/errors.go index 823ab00..058ae2e 100644 --- a/pkg/api/handlers/errors/errors.go +++ b/pkg/api/handlers/errors/errors.go @@ -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{}{ diff --git a/pkg/utils/constants/constants.go b/pkg/utils/constants/constants.go index 2af32e9..1a32fba 100644 --- a/pkg/utils/constants/constants.go +++ b/pkg/utils/constants/constants.go @@ -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" @@ -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" ) @@ -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) )