mehhttp

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 5 Imported by: 5

Documentation

Overview

Package mehhttp provides functionality for handling and responding errors.

Index

Constants

View Source
const (
	// ErrCommunication is used for all problems regarding client communication. As
	// communication is unstable by nature, this should not be reported as classic
	// meh.ErrInternal.
	ErrCommunication meh.Code = "mehhttp-communication"
	// ErrServiceNotReachable is used for problems with requesting third-party
	// services.
	ErrServiceNotReachable meh.Code = "mehhttp-service-not-reachable"
)

Variables

This section is empty.

Functions

func HTTPStatusCode added in v1.10.0

func HTTPStatusCode(e error) int

HTTPStatusCode retrieves the HTTP status code for the given error.

func LogAndRespondError

func LogAndRespondError(logger *zap.Logger, w http.ResponseWriter, r *http.Request, e error)

LogAndRespondError logs the given meh.Error and responds using the status code mapping set via SetHTTPStatusCodeMapping. The responded message will always be empty.

func SetHTTPStatusCodeMapping

func SetHTTPStatusCodeMapping(mapping HTTPStatusCodeMapper)

SetHTTPStatusCodeMapping sets the mapping of meh.Code to HTTP status code that is used in LogAndRespondError.

Types

type HTTPStatusCodeMapper

type HTTPStatusCodeMapper func(code meh.Code) int

HTTPStatusCodeMapper maps a meh.Code to HTTP status code. Used for example in LogAndRespondError.

Jump to

Keyboard shortcuts

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