Package problem implements errors similar to the ones described by RFC7807.

import (


The package may be used under the terms of the BSD 2-Clause License a copy of which may be found in the LICENSE file.

Unless you explicitly state otherwise, any contribution submitted for inclusion in the work by you shall be licensed as above, without any additional terms or conditions.

Expand ▾ Collapse ▴



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



This section is empty.


This section is empty.


func NewResponder

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

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

func Status(status int) Problem

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

func (Problem) Error

func (p Problem) Error() string

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

func (Problem) HTTPStatus

func (p Problem) HTTPStatus() int

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

Source Files