exception

package
v0.0.0-20260608 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(next http.Handler) http.Handler

Global exception handler middleware

func RenderError

func RenderError(w http.ResponseWriter, r *http.Request, err error)

RenderError is a convenience function to render any error as an HTTP response.

Types

type HttpException

type HttpException struct {
	Code    int
	Message string
	// contains filtered or unexported fields
}

HttpException represents a generic HTTP error.

func BadGateway

func BadGateway(msg string) *HttpException

BadGateway returns a 502 HttpException.

func BadRequest

func BadRequest(msg string) *HttpException

BadRequest returns a 400 HttpException.

func Conflict

func Conflict(msg string) *HttpException

Conflict returns a 409 HttpException.

func Forbidden

func Forbidden(msg string) *HttpException

Forbidden returns a 403 HttpException.

func GatewayTimeout

func GatewayTimeout(msg string) *HttpException

GatewayTimeout returns a 504 HttpException.

func Gone

func Gone(msg string) *HttpException

Gone returns a 410 HttpException.

func InternalServerError

func InternalServerError(msg string) *HttpException

InternalServerError returns a 500 HttpException.

func NotFound

func NotFound(msg string) *HttpException

NotFound returns a 404 HttpException.

func NotImplemented

func NotImplemented(msg string) *HttpException

NotImplemented returns a 501 HttpException.

func ServiceUnavailable

func ServiceUnavailable(msg string) *HttpException

ServiceUnavailable returns a 503 HttpException.

func TooManyRequests

func TooManyRequests(msg string) *HttpException

TooManyRequests returns a 429 HttpException.

func Unauthorized

func Unauthorized(msg string) *HttpException

Unauthorized returns a 401 HttpException.

func UnprocessableEntity

func UnprocessableEntity(msg string) *HttpException

UnprocessableEntity returns a 422 HttpException.

func Wrap

func Wrap(code int, msg string, cause error) *HttpException

Wrap creates an HttpException wrapping an underlying error.

func WrapWithReport

func WrapWithReport(code int, msg string, cause error, reporter func() []string) *HttpException

WrapWithReport creates an HttpException wrapping an error with a reporter.

func (*HttpException) Error

func (e *HttpException) Error() string

func (*HttpException) Render

func (e *HttpException) Render(w http.ResponseWriter, r *http.Request)

Render outputs the exception as either JSON or HTML based on the request's Accept or Content-Type headers.

func (*HttpException) Report

func (e *HttpException) Report() []string

Report returns additional context for logging.

func (*HttpException) Unwrap

func (e *HttpException) Unwrap() error

func (*HttpException) WithHeader

func (e *HttpException) WithHeader(key, value string) *HttpException

WithHeader adds a response header to the exception.

func (*HttpException) WithReport

func (e *HttpException) WithReport(fn func() []string) *HttpException

WithReport adds a reporter function for custom log context.

type Renderable

type Renderable interface {
	error
	Render(w http.ResponseWriter, r *http.Request)
}

Renderable is an interface for exceptions that can render themselves.

type Reportable

type Reportable interface {
	error
	Report() []string // Returns additional context for logging
}

Reportable is an interface for exceptions that can report themselves.

Jump to

Keyboard shortcuts

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