errhttp

package
v0.0.0-...-fb7f86c Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNonGrafanaError = errutil.NewBase(errutil.StatusInternal, "core.MalformedError")

Functions

func Write

func Write(ctx context.Context, err error, w http.ResponseWriter, opts ...func(ErrorOptions) ErrorOptions)

Write writes an error to the provided http.ResponseWriter with the appropriate HTTP status and JSON payload from errutil.Error. Write also logs the provided error to either the "request-errors" logger, or the logger provided as a functional option using WithLogger. When passing errors that are not errors.As compatible with errutil.Error, ErrNonGrafanaError will be used to create a generic 500 Internal Server Error payload by default, this is overrideable by providing WithFallback for a custom fallback error.

Types

type ErrorOptions

type ErrorOptions struct {
	// contains filtered or unexported fields
}

ErrorOptions is a container for functional options passed to Write.

func WithFallback

func WithFallback(opt ErrorOptions, fallback errutil.Error) ErrorOptions

WithFallback sets the default error returned to the user if the error sent to Write is not an errutil.Error.

func WithLogger

func WithLogger(opt ErrorOptions, logger log.Logger) ErrorOptions

WithLogger sets the logger that Write should write log output on.

Jump to

Keyboard shortcuts

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