2025-02-23 22:34:26 +08:00
|
|
|
package response
|
|
|
|
|
|
|
|
|
|
import "net/http"
|
|
|
|
|
|
|
|
|
|
type ErrorCode struct {
|
|
|
|
|
Code string
|
|
|
|
|
Message string
|
|
|
|
|
HttpCode int
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-24 16:48:20 +08:00
|
|
|
func (e ErrorCode) Error() string {
|
|
|
|
|
return e.Code
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-23 22:34:26 +08:00
|
|
|
var (
|
|
|
|
|
// 4xx
|
2025-03-05 21:21:44 +08:00
|
|
|
ErrBadRequest = &ErrorCode{Code: "BAD_REQUEST", Message: "BAD_REQUEST", HttpCode: http.StatusBadRequest}
|
|
|
|
|
ErrUnauthorized = &ErrorCode{Code: "UNAUTHORIZED", Message: "UNAUTHORIZED", HttpCode: http.StatusUnauthorized}
|
|
|
|
|
ErrDBRequest = &ErrorCode{Code: "BAD_DB_REQUEST", Message: "DB_ERROR", HttpCode: http.StatusBadRequest}
|
|
|
|
|
ErrExpiryToken = &ErrorCode{Code: "EXPIRED_TOKEN", Message: "EXPIRED_TOKEN", HttpCode: http.StatusUnauthorized}
|
2025-02-24 16:48:20 +08:00
|
|
|
|
|
|
|
|
// 5xx
|
|
|
|
|
ErrMarshal = &ErrorCode{Code: "FAILED_MARSHAL", Message: "FAILED_MARSHAL_BODY", HttpCode: http.StatusInternalServerError}
|
|
|
|
|
ErrCreateEntity = &ErrorCode{Code: "FAILED_CREATE_ENTITY", Message: "FAILED_CREATE_ENTITY", HttpCode: http.StatusInternalServerError}
|
|
|
|
|
|
|
|
|
|
// redis
|
|
|
|
|
ErrRedisConnNotFound = &ErrorCode{Code: "FAILED_CONNECT_REDIS", Message: "REDIS_NOT_FOUND", HttpCode: http.StatusInternalServerError}
|
|
|
|
|
ErrRedisSet = &ErrorCode{Code: "FAILED_SET_REDIS", Message: "FAILED_CACHING", HttpCode: http.StatusInternalServerError}
|
2025-02-23 22:34:26 +08:00
|
|
|
)
|