Documentation
¶
Overview ¶
Package errutil provides utility functions for handling and responding to errors in HTTP handlers.
Index ¶
- func AuthenticationRequiredResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)
- func BadRequestResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, err error)
- func ErrorResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, status int, ...)
- func FailedValidationResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, ...)
- func InactiveAccountResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)
- func InvalidAuthenticationTokenResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)
- func LogError(r *http.Request, logger *slog.Logger, err error)
- func NotFoundResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)
- func ServerErrorResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequestResponse ¶
BadRequestResponse sends a 400 Bad Request response with the provided error message.
func ErrorResponse ¶
func ErrorResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, status int, message any)
ErrorResponse sends a JSON response with the specified status code and error message. If writing the JSON response fails, it logs the error and sends a 500 Internal Server Error response.
func FailedValidationResponse ¶
func FailedValidationResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, errors map[string]string)
FailedValidationResponse sends a 422 Unprocessable Entity response with the provided validation errors.
func InactiveAccountResponse ¶
func NotFoundResponse ¶
NotFoundResponse sends a 404 Not Found response with a standard error message indicating the resource could not be found.
func ServerErrorResponse ¶
ServerErrorResponse logs the provided error and sends a 500 Internal Server Error response with a standard error message.
Types ¶
This section is empty.