problem

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPayload    = errors.New("invalid problem")
	ErrInvalidParameters = errors.New("invalid parameters")
	ErrUnexpected        = errors.New("unexpected error")
	ErrForbidden         = errors.New("forbidden")
)

Differents problem issues

View Source
var DefaultForbidden = ForbiddenProblem{
	Payload: &Payload{
		Type:   "about:blank",
		Title:  "Your are missing credentials or have insufficient rights",
		Status: http.StatusForbidden,
	},
}
View Source
var DefaultInput = Input{
	Payload: &Payload{
		Type:   "about:blank",
		Title:  "Your parameters didn't validate",
		Status: http.StatusBadRequest,
	},
}
View Source
var DefaultUnexpected = UnexpectedProblem{
	Payload: &Payload{
		Type:   "about:blank",
		Title:  "An unexpected error occured decoding request",
		Status: http.StatusInternalServerError,
	},
}

Functions

This section is empty.

Types

type ForbiddenProblem added in v0.2.1

type ForbiddenProblem struct {
	*Payload
}

ForbiddenProblem problem

func (ForbiddenProblem) Error added in v0.2.1

func (f ForbiddenProblem) Error() string

Error implements error interface

func (ForbiddenProblem) Send added in v0.2.1

Send implements Problem interface

type Input

type Input struct {
	*Payload
	InvalidParams []ParamError `json:"invalid_parameters"`
}

Input extends a standard problem problem with invalid parameters

func (Input) Error

func (i Input) Error() string

Error implement error interface

func (Input) Send

func (i Input) Send(w http.ResponseWriter)

Send implements Problem interface

type ParamError

type ParamError struct {
	Field  string `json:"field"`
	Reason string `json:"reason"`
}

ParamError describe an error on a specific parameter

type Payload

type Payload struct {
	Type   string `json:"type"`
	Title  string `json:"title"`
	Status int    `json:"status"`
}

Payload represents most basic problem of an `application/problem+json` response.

func (Payload) Send added in v0.2.3

func (p Payload) Send(w http.ResponseWriter)

Send implements Problem

func (*Payload) Validate

func (p *Payload) Validate() error

Validate provides validation and sets default values if needed

type Problem

type Problem interface {
	Send(http.ResponseWriter)
}

type UnexpectedProblem

type UnexpectedProblem struct {
	*Payload
}

UnexpectedProblem problem

func (UnexpectedProblem) Error

func (u UnexpectedProblem) Error() string

Error implements error interface

func (UnexpectedProblem) Send

Send implements Problem interface

Jump to

Keyboard shortcuts

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