Documentation
¶
Overview ¶
Package errors provides custom error types and error handling utilities for Nivo services.
Index ¶
- func As(err error, target interface{}) bool
- func GetHTTPStatus(err error) int
- func Is(err error, target error) bool
- func IsForbidden(err error) bool
- func IsInternal(err error) bool
- func IsNotFound(err error) bool
- func IsUnauthorized(err error) bool
- func IsValidation(err error) bool
- type Error
- func AccountFrozen(message string) *Error
- func BadRequest(message string) *Error
- func Conflict(message string) *Error
- func Database(message string) *Error
- func DatabaseWrap(err error, message string) *Error
- func DuplicateIdempotencyKey(key string) *Error
- func Forbidden(message string) *Error
- func Gone(message string) *Error
- func InsufficientFunds(message string) *Error
- func Internal(message string) *Error
- func InternalWrap(err error, message string) *Error
- func InvalidOTP(attemptsRemaining int) *Error
- func LimitExceeded(message string) *Error
- func New(code ErrorCode, message string) *Error
- func NotFound(resource string) *Error
- func NotFoundWithID(resource, id string) *Error
- func Timeout(message string) *Error
- func TooManyRequests(message string) *Error
- func TransactionFailed(message string) *Error
- func Unauthorized(message string) *Error
- func Unavailable(message string) *Error
- func Validation(message string) *Error
- func ValidationWithFields(message string, fields map[string]string) *Error
- func VerificationExpired() *Error
- func VerificationRequired(message string) *Error
- func Wrap(err error, code ErrorCode, message string) *Error
- func Wrapf(err error, code ErrorCode, format string, args ...interface{}) *Error
- type ErrorCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetHTTPStatus ¶
GetHTTPStatus extracts the HTTP status code from an error.
func IsForbidden ¶
IsForbidden checks if an error is a forbidden error.
func IsInternal ¶
IsInternal checks if an error is an internal server error.
func IsNotFound ¶
IsNotFound checks if an error is a not found error.
func IsUnauthorized ¶
IsUnauthorized checks if an error is an unauthorized error.
func IsValidation ¶
IsValidation checks if an error is a validation error.
Types ¶
type Error ¶
type Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Details map[string]interface{} `json:"details,omitempty"`
Err error `json:"-"` // Underlying error (not exposed in JSON)
}
Error represents a structured error with code, message, and details.
func AccountFrozen ¶
AccountFrozen creates an account frozen error.
func DatabaseWrap ¶
DatabaseWrap wraps a database error.
func DuplicateIdempotencyKey ¶
DuplicateIdempotencyKey creates a duplicate idempotency key error.
func InsufficientFunds ¶
InsufficientFunds creates an insufficient funds error.
func InternalWrap ¶
InternalWrap wraps an error as an internal server error.
func InvalidOTP ¶
InvalidOTP creates an invalid OTP error. attemptsRemaining indicates how many more attempts the user has.
func LimitExceeded ¶
LimitExceeded creates a limit exceeded error.
func NotFoundWithID ¶
NotFoundWithID creates a not found error with resource ID.
func TooManyRequests ¶
TooManyRequests creates a rate limit exceeded error.
func TransactionFailed ¶
TransactionFailed creates a transaction failed error.
func Unauthorized ¶
Unauthorized creates an unauthorized error.
func Unavailable ¶
Unavailable creates a service unavailable error.
func ValidationWithFields ¶
ValidationWithFields creates a validation error with field details.
func VerificationExpired ¶
func VerificationExpired() *Error
VerificationExpired creates a verification expired error. Used when a verification request has expired and is no longer valid.
func VerificationRequired ¶
VerificationRequired creates a verification required error. Used when an operation requires OTP verification to proceed.
func (*Error) HTTPStatusCode ¶
HTTPStatusCode returns the appropriate HTTP status code for this error.
func (*Error) WithDetails ¶
WithDetails adds details to the error.
type ErrorCode ¶
type ErrorCode string
ErrorCode represents a specific error type that can be used by clients.
const ( // Client errors (4xx) ErrCodeNotFound ErrorCode = "NOT_FOUND" ErrCodeBadRequest ErrorCode = "BAD_REQUEST" ErrCodeValidation ErrorCode = "VALIDATION_ERROR" ErrCodeForbidden ErrorCode = "FORBIDDEN" ErrCodeConflict ErrorCode = "CONFLICT" ErrCodeRateLimit ErrorCode = "RATE_LIMIT_EXCEEDED" ErrCodePrecondition ErrorCode = "PRECONDITION_FAILED" ErrCodeInsufficientFunds ErrorCode = "INSUFFICIENT_FUNDS" // Server errors (5xx) ErrCodeInternal ErrorCode = "INTERNAL_ERROR" ErrCodeTimeout ErrorCode = "TIMEOUT" ErrCodeDatabaseError ErrorCode = "DATABASE_ERROR" // Domain-specific errors ErrCodeInvalidAmount ErrorCode = "INVALID_AMOUNT" ErrCodeInvalidCurrency ErrorCode = "INVALID_CURRENCY" ErrCodeAccountFrozen ErrorCode = "ACCOUNT_FROZEN" ErrCodeTransactionFailed ErrorCode = "TRANSACTION_FAILED" ErrCodeDuplicateIdempotencyKey ErrorCode = "DUPLICATE_IDEMPOTENCY_KEY" // Verification errors ErrCodeVerificationRequired ErrorCode = "VERIFICATION_REQUIRED" ErrCodeVerificationExpired ErrorCode = "VERIFICATION_EXPIRED" ErrCodeInvalidOTP ErrorCode = "INVALID_OTP" ErrCodeLimitExceeded ErrorCode = "LIMIT_EXCEEDED" ErrCodeGone ErrorCode = "GONE" )
Error codes for common error scenarios.
func GetErrorCode ¶
GetErrorCode extracts the error code from an error if it's a custom Error.