problem: Index | Files

package problem

import ""

Package problem implements errors similar to the ones described by RFC 7807.


Package Files


func NewResponder Uses

func NewResponder() func(http.ResponseWriter, *http.Request, error) error

NewResponder returns a function that can be used to reply to HTTP requests with errors. If the error is a Problem or has an HTTPStatus method returning an int, its status code is used (or 500 if no status code was specified). If the HTTPStatus method returns 0, no status code is written and the user must write one elsewhere. If the error value is nil, a 200 is returned.

type Problem Uses

type Problem struct {
    // A URI reference that identifies the problem type.
    Type string `json:"type,omitempty"`

    // A short, human-readable summary of the problem type.
    Title string `json:"title,omitempty"`

    // The HTTP status code generated by the origin server for this occurrence of
    // the problem.
    Status int `json:"status,omitempty"`

    // A human-readable explanation specific to this occurrence of the problem.
    Detail string `json:"detail,omitempty"`

    // A URI reference that identifies the specific occurrence of the problem.
    Instance string `json:"instance,omitempty"`

Problem respresents an unrecoverable error that occured during processing of an API request. Problems are designed to be embedded in application or endpoint specific error types. Consumers must use the "type" string as the primary identifier for the problem type.

func Status Uses

func Status(status int) Problem

Status returns a problem for the provided HTTP status code that conveys no additional information.

func (Problem) Error Uses

func (p Problem) Error() string

Error satisfies the error interface for Problem by returning the title.

func (Problem) HTTPStatus Uses

func (p Problem) HTTPStatus() int

HTTPStatus returns the HTTP status as set by the origin server before encoding the problem.

Package problem imports 3 packages (graph). Updated 2020-01-24. Refresh now. Tools for package owners.