Back to godoc.org
code.soquee.net/problem

Package problem

v0.0.2
Latest Go to latest

The latest major version is .

Published: May 29, 2019 | License: BSD-2-Clause | Module: code.soquee.net/problem

Overview

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

Index

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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier