Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.