httperror

package module
v0.0.0-...-88b434d Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(err1, err2 error) bool

Equal compares error status codes and contents.

func New

func New(code int, format string, a ...interface{}) error

New constructs a new HTTPError.

func StatusCode

func StatusCode(err error) int

StatusCode is a convenience function for extracting HTTP Status Code from error types. It returns 200 for nil errors, embedded StatusCode for HTTPError instances, and 500 in every other case.

func StatusText

func StatusText(err error) string

StatusText is a convenience function for extracting HTTP status text from error types.

func Write

func Write(w http.ResponseWriter, err error)

Write to the response writer a status code and a JSON-encoded message based on the provided error. The payload will look like:

{
		"message": "error writing to DB"
}

In case the status code is 500 (Internal Server Error), the message will always be "Internal Server Error". Write does not end the request; the caller should ensure no further writes are done to w.

Types

type HTTPError

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

HTTPError is a convenience error type for returning function processing results back to callers.

func (*HTTPError) Error

func (p *HTTPError) Error() string

Error function transforms HTTPError into a human-readable string.

Jump to

Keyboard shortcuts

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