httperror

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package httperror defines the format for HTTP error responses from Chain services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter struct {
	Default     Info
	IsTemporary func(info Info, err error) bool
	Errors      map[error]Info
}

Formatter defines rules for mapping errors to the Chain error response format.

func (Formatter) Format

func (f Formatter) Format(err error) (body Response)

Format builds an error Response body describing err by consulting the f.Errors lookup table. If no entry is found, it returns f.Default.

func (Formatter) Write

func (f Formatter) Write(ctx context.Context, w http.ResponseWriter, err error)

Write writes a json encoded Response to the ResponseWriter. It uses the status code associated with the error.

Write may be used as an ErrorWriter in the httpjson package.

type Info

type Info struct {
	HTTPStatus int    `json:"-"`
	ChainCode  string `json:"code"`
	Message    string `json:"msg"`
}

Info contains a set of error codes to send to the user.

type Response

type Response struct {
	Info
	Status    string                 `json:"status,omitempty"`
	Detail    string                 `json:"detail,omitempty"`
	Data      map[string]interface{} `json:"data,omitempty"`
	Temporary bool                   `json:"temporary"`
}

Response defines the error response for a Chain error.

Jump to

Keyboard shortcuts

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