Documentation
¶
Index ¶
- Constants
- Variables
- func IsErr(err error, target *Error) bool
- func IsErrRecordNotFound(err error) bool
- type Error
- func AsErr(err error) (Error, bool)
- func Err(message string) Error
- func ErrWithCode(code int, message string) Error
- func ErrWithCodeAndStatus(code, status int, message string) Error
- func ErrWithCodeAndStatusf(code, status int, messageFormat string, args ...any) *Error
- func ErrWithCodef(code int, messageFormat string, args ...any) Error
- func Errf(messageFormat string, args ...any) Error
- type Result
Constants ¶
View Source
const ( // Message IDs for i18n (used as keys in locale files). OkMessage = "ok" // OkMessage is the i18n key for ok response OkCode = 0 // OkCode is the code for ok response ErrMessage = "error" // ErrMessage is the i18n key for error response ErrMessageRecordNotFound = "record_not_found" // ErrMessageRecordNotFound is the i18n key for record not found error ErrMessageRecordAlreadyExists = "record_already_exists" // ErrMessageRecordAlreadyExists is the i18n key for record already exists error ErrMessageUnknown = "unknown_error" // ErrMessageUnknown is the i18n key for unknown error ErrMessageNotFound = "not_found" // ErrMessageNotFound is the i18n key for not found error ErrMessageTooManyRequests = "too_many_requests" // ErrMessageTooManyRequests is the i18n key for too many requests error ErrMessageUnauthenticated = "unauthenticated" // ErrMessageUnauthenticated is the i18n key for unauthenticated error ErrMessageTokenExpired = "token_expired" // ErrMessageTokenExpired is the i18n key for expired token error ErrMessageTokenInvalid = "token_invalid" // ErrMessageTokenInvalid is the i18n key for invalid token error ErrMessageTokenNotValidYet = "token_not_valid_yet" // ErrMessageTokenNotValidYet is the i18n key for not valid yet error ErrMessageTokenInvalidIssuer = "token_invalid_issuer" // ErrMessageTokenInvalidIssuer is the i18n key for invalid issuer error ErrMessageTokenInvalidAudience = "token_invalid_audience" // ErrMessageTokenInvalidAudience is the i18n key for invalid audience error ErrMessageTokenMissingSubject = "token_missing_subject" // ErrMessageTokenMissingSubject is the i18n key for missing subject error ErrMessageTokenMissingTokenType = "token_missing_token_type" // ErrMessageTokenMissingTokenType is the i18n key for missing token type error ErrMessageAppIdRequired = "app_id_required" // ErrMessageAppIdRequired is the i18n key for app id required error ErrMessageTimestampRequired = "timestamp_required" // ErrMessageTimestampRequired is the i18n key for app timestamp required error ErrMessageSignatureRequired = "signature_required" // ErrMessageSignatureRequired is the i18n key for app signature required error ErrMessageTimestampInvalid = "timestamp_invalid" // ErrMessageTimestampInvalid is the i18n key for app timestamp invalid error ErrMessageSignatureExpired = "signature_expired" // ErrMessageSignatureExpired is the i18n key for app signature expired error ErrMessageExternalAppNotFound = "external_app_not_found" // ErrMessageExternalAppNotFound is the i18n key for app not found error ErrMessageExternalAppDisabled = "external_app_disabled" // ErrMessageExternalAppDisabled is the i18n key for app disabled error ErrMessageIpNotAllowed = "ip_not_allowed" // ErrMessageIpNotAllowed is the i18n key for app ip not allowed error ErrMessageSignatureInvalid = "signature_invalid" // ErrMessageSignatureInvalid is the i18n key for app signature invalid error ErrMessageAccessDenied = "access_denied" // ErrMessageAccessDenied is the i18n key for access denied error ErrMessageUnsupportedMediaType = "unsupported_media_type" // ErrMessageUnsupportedMediaType is the i18n key for unsupported media type error ErrMessageRequestTimeout = "request_timeout" // ErrMessageRequestTimeout is the i18n key for request timeout error ErrCodeDefault = 2000 // ErrCodeDefault is the default code for error response (2000 and above are business error codes) ErrCodeRecordNotFound = 2001 // ErrCodeRecordNotFound is the code for record not found error ErrCodeRecordAlreadyExists = 2002 // ErrCodeRecordAlreadyExists is the code for record already exists error ErrCodeUnknown = 1900 // ErrCodeUnknown is the code for unknown error ErrCodeBadRequest = 1400 // ErrCodeBadRequest is the code for bad request error ErrCodeTooManyRequests = 1401 // ErrCodeTooManyRequests is the code for too many requests error ErrCodeUnauthenticated = 1000 // ErrCodeUnauthenticated is the code for unauthenticated error ErrCodeUnsupportedAuthenticationType = 1001 // ErrCodeUnsupportedAuthenticationType is the code for unsupported authentication type error ErrCodeTokenExpired = 1002 // ErrCodeTokenExpired is the code for expired token error ErrCodeTokenInvalid = 1003 // ErrCodeTokenInvalid is the code for invalid token error ErrCodeTokenNotValidYet = 1004 // ErrCodeTokenNotValidYet is the code for not valid yet error ErrCodeTokenInvalidIssuer = 1005 // ErrCodeTokenInvalidIssuer is the code for invalid issuer error ErrCodeTokenInvalidAudience = 1007 // ErrCodeTokenInvalidAudience is the code for invalid audience error ErrCodeTokenMissingSubject = 1008 // ErrCodeTokenMissingSubject is the code for missing subject error ErrCodeTokenMissingTokenType = 1009 // ErrCodeTokenMissingTokenType is the code for missing token type error ErrCodePrincipalInvalid = 1010 // ErrCodePrincipalInvalid is the code for invalid principal error ErrCodeCredentialsInvalid = 1011 // ErrCodeCredentialsInvalid is the code for invalid credentials error ErrCodeAppIdRequired = 1012 // ErrCodeAppIdRequired is the code for app id required error ErrCodeTimestampRequired = 1013 // ErrCodeTimestampRequired is the code for app timestamp required error ErrCodeSignatureRequired = 1014 // ErrCodeSignatureRequired is the code for app signature required error ErrCodeTimestampInvalid = 1015 // ErrCodeTimestampInvalid is the code for app timestamp invalid error ErrCodeSignatureExpired = 1016 // ErrCodeSignatureExpired is the code for app signature expired error ErrCodeExternalAppNotFound = 1017 // ErrCodeExternalAppNotFound is the code for app not found error ErrCodeExternalAppDisabled = 1018 // ErrCodeExternalAppDisabled is the code for app disabled error ErrCodeIpNotAllowed = 1019 // ErrCodeIpNotAllowed is the code for ip not allowed error ErrCodeSignatureInvalid = 1020 // ErrCodeSignatureInvalid is the code for app signature invalid error ErrCodeAccessDenied = 1100 // ErrCodeAccessDenied is the code for access denied error ErrCodeNotFound = 1200 // ErrCodeNotFound is the code for not found error ErrCodeUnsupportedMediaType = 1300 // ErrCodeUnsupportedMediaType is the code for unsupported media type error ErrCodeRequestTimeout = 1400 // ErrCodeRequestTimeout is the code for request timeout error ErrCodeNotImplemented = 1500 // ErrCodeNotImplemented is the code for not implemented error )
Variables ¶
View Source
var ( ErrTokenExpired = ErrWithCodeAndStatus( ErrCodeTokenExpired, fiber.StatusUnauthorized, i18n.T(ErrMessageTokenExpired), ) // ErrTokenExpired is the error for expired token ErrTokenInvalid = ErrWithCodeAndStatus( ErrCodeTokenInvalid, fiber.StatusUnauthorized, i18n.T(ErrMessageTokenInvalid), ) // ErrTokenInvalid is the error for invalid token ErrTokenNotValidYet = ErrWithCodeAndStatus( ErrCodeTokenNotValidYet, fiber.StatusUnauthorized, i18n.T(ErrMessageTokenNotValidYet), ) // ErrTokenNotValidYet is the error for not valid yet token ErrTokenInvalidIssuer = ErrWithCodeAndStatus( ErrCodeTokenInvalidIssuer, fiber.StatusUnauthorized, i18n.T(ErrMessageTokenInvalidIssuer), ) // ErrTokenInvalidIssuer is the error for invalid issuer token ErrTokenInvalidAudience = ErrWithCodeAndStatus( ErrCodeTokenInvalidAudience, fiber.StatusUnauthorized, i18n.T(ErrMessageTokenInvalidAudience), ) // ErrTokenInvalidAudience is the error for invalid audience token ErrTokenMissingSubject = ErrWithCodeAndStatus( ErrCodeTokenMissingSubject, fiber.StatusUnauthorized, i18n.T(ErrMessageTokenMissingSubject), ) // ErrTokenMissingSubject is the error for missing subject token ErrTokenMissingTokenType = ErrWithCodeAndStatus( ErrCodeTokenMissingTokenType, fiber.StatusUnauthorized, i18n.T(ErrMessageTokenMissingTokenType), ) // ErrTokenMissingTokenType is the error for missing token type token ErrAppIdRequired = ErrWithCodeAndStatus(ErrCodeAppIdRequired, fiber.StatusUnauthorized, i18n.T(ErrMessageAppIdRequired)) // ErrAppIdRequired is the error for missing app id ErrTimestampRequired = ErrWithCodeAndStatus( ErrCodeTimestampRequired, fiber.StatusUnauthorized, i18n.T(ErrMessageTimestampRequired), ) // ErrTimestampRequired is the error for missing app timestamp ErrSignatureRequired = ErrWithCodeAndStatus( ErrCodeSignatureRequired, fiber.StatusUnauthorized, i18n.T(ErrMessageSignatureRequired), ) // ErrSignatureRequired is the error for missing app signature ErrTimestampInvalid = ErrWithCodeAndStatus( ErrCodeTimestampInvalid, fiber.StatusUnauthorized, i18n.T(ErrMessageTimestampInvalid), ) // ErrTimestampInvalid is the error for invalid app timestamp ErrSignatureExpired = ErrWithCodeAndStatus( ErrCodeSignatureExpired, fiber.StatusUnauthorized, i18n.T(ErrMessageSignatureExpired), ) // ErrSignatureExpired is the error for expired app signature ErrSignatureInvalid = ErrWithCodeAndStatus( ErrCodeSignatureInvalid, fiber.StatusUnauthorized, i18n.T(ErrMessageSignatureInvalid), ) // ErrSignatureInvalid is the error for invalid app signature ErrExternalAppNotFound = ErrWithCodeAndStatus( ErrCodeExternalAppNotFound, fiber.StatusUnauthorized, i18n.T(ErrMessageExternalAppNotFound), ) // ErrExternalAppNotFound is the error for app not found ErrExternalAppDisabled = ErrWithCodeAndStatus( ErrCodeExternalAppDisabled, fiber.StatusUnauthorized, i18n.T(ErrMessageExternalAppDisabled), ) // ErrExternalAppDisabled is the error for app disabled ErrIpNotAllowed = ErrWithCodeAndStatus(ErrCodeIpNotAllowed, fiber.StatusUnauthorized, i18n.T(ErrMessageIpNotAllowed)) // ErrIpNotAllowed is the error for ip not allowed ErrUnauthenticated = ErrWithCodeAndStatus(ErrCodeUnauthenticated, fiber.StatusUnauthorized, i18n.T(ErrMessageUnauthenticated)) // ErrUnauthenticated is the error for unauthenticated ErrAccessDenied = ErrWithCodeAndStatus(ErrCodeAccessDenied, fiber.StatusForbidden, i18n.T(ErrMessageAccessDenied)) // ErrAccessDenied is the error for access denied ErrUnknown = ErrWithCodeAndStatus(ErrCodeUnknown, fiber.StatusInternalServerError, i18n.T(ErrMessageUnknown)) // ErrUnknown is the error for unknown error ErrRecordNotFound = ErrWithCode( ErrCodeRecordNotFound, i18n.T(ErrMessageRecordNotFound), ) // ErrRecordNotFound is the error for record not found ErrRecordAlreadyExists = ErrWithCode( ErrCodeRecordAlreadyExists, i18n.T(ErrMessageRecordAlreadyExists), ) // ErrRecordAlreadyExists is the error for record already exists )
Functions ¶
func IsErrRecordNotFound ¶
IsErrRecordNotFound checks if the error is a record not found error.
Types ¶
type Error ¶
type Error struct {
Code int // Code is the error code
Message string // Message is the error message
Status int // Status is the HTTP status code
}
Error is a custom application error type that implements the error interface.
func ErrWithCode ¶
ErrWithCode creates a new Error with a code.
func ErrWithCodeAndStatus ¶
ErrWithCodeAndStatus creates a new Error with a code and status.
func ErrWithCodeAndStatusf ¶
ErrWithCodeAndStatusf creates a new Error with a formatted message, code and status.
func ErrWithCodef ¶
ErrWithCodef creates a new Error with a formatted message and code.
type Result ¶
type Result struct {
Code int `json:"code"` // Code is the response code
Message string `json:"message"` // Message is the response message
Data any `json:"data"` // Data is the response data
}
The Result is a struct that represents a result of an Api call.
func OkWithMessage ¶
OkWithMessage creates a new Result with the given message and data.
Click to show internal directories.
Click to hide internal directories.