errors

package
v0.0.0-...-e705344 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package errutil provides utility functions for handling and responding to errors in HTTP handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticationRequiredResponse

func AuthenticationRequiredResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

func BadRequestResponse

func BadRequestResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, err error)

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 InactiveAccountResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

func InvalidAuthenticationTokenResponse

func InvalidAuthenticationTokenResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

func LogError

func LogError(r *http.Request, logger *slog.Logger, err error)

LogError logs the provided error along with the HTTP method and request URI.

func NotFoundResponse

func NotFoundResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

NotFoundResponse sends a 404 Not Found response with a standard error message indicating the resource could not be found.

func ServerErrorResponse

func ServerErrorResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, err error)

ServerErrorResponse logs the provided error and sends a 500 Internal Server Error response with a standard error message.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL