Documentation
¶
Index ¶
- Constants
- func Module() fx.Option
- func New(config Config, option Options, logger *zap.Logger) *fiber.App
- func NewCustomJSONErrorHandler(logger *zap.Logger, formatter ErrorFormatter) fiber.ErrorHandler
- func NewJSONErrorHandler(logger *zap.Logger) fiber.ErrorHandler
- func NewViewsErrorHandler(logger *zap.Logger, template string, layouts ...string) fiber.ErrorHandler
- type Config
- type ErrorFormatter
- type ErrorResponse
- type Options
Constants ¶
const StatusClientClosedRequest = 499
StatusClientClosedRequest is the HTTP status code for client closed request errors.
Variables ¶
This section is empty.
Functions ¶
func NewCustomJSONErrorHandler ¶
func NewCustomJSONErrorHandler(logger *zap.Logger, formatter ErrorFormatter) fiber.ErrorHandler
NewCustomJSONErrorHandler returns a fiber.ErrorHandler that formats the given error and HTTP status code using the provided ErrorFormatter, and sends the result as a JSON response. If the formatter is nil, it falls back to using NewErrorResponse to format the error.
func NewJSONErrorHandler ¶
func NewJSONErrorHandler(logger *zap.Logger) fiber.ErrorHandler
NewJSONErrorHandler returns a fiber.ErrorHandler that formats the given error and HTTP status code using the NewErrorResponse function, and sends the result as a JSON response.
func NewViewsErrorHandler ¶
func NewViewsErrorHandler(logger *zap.Logger, template string, layouts ...string) fiber.ErrorHandler
NewViewsErrorHandler creates a fiber.ErrorHandler that renders the given template with the error message and status code. If rendering fails, it falls back to sending the error message as a plain-text response. The logger is used to log errors that occur while rendering the view. The layouts are passed to the Render method as is.
Types ¶
type ErrorFormatter ¶
ErrorFormatter formats an error and HTTP status code into a JSON-serializable payload.
type ErrorResponse ¶
type ErrorResponse struct {
Message string `json:"message"`
Code int `json:"code,omitempty"`
Details any `json:"details,omitempty"`
}
func NewErrorResponse ¶
func NewErrorResponse(message string, code int, details any) ErrorResponse
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func (*Options) WithErrorHandler ¶
func (o *Options) WithErrorHandler(handler fiber.ErrorHandler) *Options