Documentation
¶
Index ¶
- Constants
- type AppError
- func BadRequest(message string) *AppError
- func Conflict(message string) *AppError
- func Forbidden(message string) *AppError
- func Internal(err error) *AppError
- func NotFound(message string) *AppError
- func RateLimited(message string) *AppError
- func ServiceUnavailable(message string) *AppError
- func Timeout(message string) *AppError
- func Unauthorized(message string) *AppError
- func Unprocessable(message string) *AppError
Constants ¶
View Source
const ( CodeNotFound = "NOT_FOUND" CodeBadRequest = "BAD_REQUEST" CodeInternalError = "INTERNAL_ERROR" CodeForbidden = "FORBIDDEN" CodeConflict = "CONFLICT" CodeUnprocessable = "UNPROCESSABLE" CodeValidationFailed = "VALIDATION_FAILED" CodeTimeout = "TIMEOUT" CodeRateLimited = "RATE_LIMITED" CodePayloadTooLarge = "PAYLOAD_TOO_LARGE" CodeMethodNotAllowed = "METHOD_NOT_ALLOWED" CodeNotAcceptable = "NOT_ACCEPTABLE" CodeGone = "GONE" CodePreconditionFailed = "PRECONDITION_FAILED" CodeTooManyRequests = "TOO_MANY_REQUESTS" CodeUnsupportedMedia = "UNSUPPORTED_MEDIA_TYPE" CodeInsufficientStorage = "INSUFFICIENT_STORAGE" CodeNotImplemented = "NOT_IMPLEMENTED" )
Standard error code constants for machine-readable error identification. Use these with WithCode() or rely on the factory defaults.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppError ¶
type AppError struct {
Status int // HTTP status code (e.g., 404, 500)
Code string // Machine-readable error code (e.g., "NOT_FOUND", "VALIDATION_FAILED")
Message string // User-facing safe message
Err error // Internal error (logged, never exposed in production)
}
AppError represents a structured application error with HTTP status context.
func RateLimited ¶ added in v2.7.1
RateLimited creates a 429 error.
func ServiceUnavailable ¶ added in v2.7.1
ServiceUnavailable creates a 503 error.
func Unprocessable ¶
Unprocessable creates a 422 error.
func (*AppError) ErrorResponse ¶
ErrorResponse returns a map for JSON error responses. In debug mode, it includes internal error details. In production, only the safe message.
func (*AppError) HTTPStatus ¶ added in v2.5.0
HTTPStatus returns the HTTP status code. Deprecated: Access .Status directly instead.
Click to show internal directories.
Click to hide internal directories.