Documentation
¶
Index ¶
- func GetStatus(err error) int
- type Error
- func New(status int, message string, args ...interface{}) *Error
- func NewBadRequest(message string, args ...interface{}) *Error
- func NewConflict(message string, args ...interface{}) *Error
- func NewForbidden(message string, args ...interface{}) *Error
- func NewInternalServerError(err error, message string, args ...interface{}) *Error
- func NewNotFound(message string, args ...interface{}) *Error
- func NewUnauthorized(message string, args ...interface{}) *Error
- func Wrap(err error, status int, message string, args ...interface{}) *Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct {
// Status is the HTTP status code associated with the error.
Status int `json:"status"`
// Message is a human-readable description of the error.
Message string `json:"message"`
// Details provides optional additional context (e.g., validation errors).
Details interface{} `json:"details,omitempty"`
// Cause is the underlying error that triggered this one, if any.
// It is excluded from JSON serialization to prevent leaking internal details.
Cause error `json:"-"`
}
Error represents a standardized application error that can be serialized to JSON. It implements the standard error interface.
func NewBadRequest ¶
NewBadRequest creates a 400 Bad Request error.
func NewConflict ¶
NewConflict creates a 409 Conflict error.
func NewForbidden ¶
NewForbidden creates a 403 Forbidden error.
func NewInternalServerError ¶
NewInternalServerError creates a 500 Internal Server Error. It automatically wraps the original error.
func NewNotFound ¶
NewNotFound creates a 404 Not Found error.
func NewUnauthorized ¶
NewUnauthorized creates a 401 Unauthorized error.
func (*Error) Unwrap ¶
Unwrap returns the underlying cause of the error, allowing usage with errors.Is and errors.As.
func (*Error) WithDetails ¶
WithDetails adds additional details to the error (e.g., validation map) and returns the error.