util

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteError

func WriteError(w http.ResponseWriter, err error, defaultStatusCode int)

WriteError writes any error to the response, checking for HTTPStatusError interface If the error implements HTTPStatusError, uses its status code, otherwise uses defaultStatusCode

func WriteJsonError

func WriteJsonError(w http.ResponseWriter, msg string, statusCode int)

Types

type HTTPError

type HTTPError struct {
	Message    string
	StatusCode int
	Cause      error
}

HTTPError represents an error with an associated HTTP status code

func NewBadRequestError

func NewBadRequestError(message string, cause error) *HTTPError

Common HTTP error constructors

func NewForbiddenError

func NewForbiddenError(message string, cause error) *HTTPError

func NewHTTPError

func NewHTTPError(statusCode int, message string, cause error) *HTTPError

NewHTTPError creates a new HTTPError

func NewInternalServerError

func NewInternalServerError(message string, cause error) *HTTPError

func NewNotFoundError

func NewNotFoundError(message string, cause error) *HTTPError

func (*HTTPError) Error

func (e *HTTPError) Error() string

func (*HTTPError) GetStatusCode

func (e *HTTPError) GetStatusCode() int

func (*HTTPError) Unwrap

func (e *HTTPError) Unwrap() error

type HTTPStatusError

type HTTPStatusError interface {
	error
	GetStatusCode() int
}

HTTPStatusError interface for errors that have an associated HTTP status code

Jump to

Keyboard shortcuts

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