errors

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: Apache-2.0 Imports: 3 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertIsHTTPErrOfCode

func AssertIsHTTPErrOfCode(t *testing.T, err error, code int)

AssertIsHTTPErrOfCode performs 4 assertions: 0. err is actually an error 1. err is an HTTPErr instance 2. err.Code = the given code 3. err.Inner != nil

Types

type HTTPErr

type HTTPErr struct {
	Code  int   // The HTTP error code to use for this error
	Inner error // The actual error of this HTTPErr struct
}

HTTPErr provides a basic struct to pass up which HTTP status code should be used with this error

func MakeBadRequestHTTPErr

func MakeBadRequestHTTPErr(err error) *HTTPErr

MakeBadRequestHTTPErr is a wrapper for MakeHTTPErr that passes in http.StatusBadRequest, since we use that response quite often

func MakeHTTPErr

func MakeHTTPErr(code int, err error) *HTTPErr

MakeHTTPErr constructs an HTTPErr instance: this mainly makes it a bit easier to read and pass into return statements

func MakeInternalHTTPErr

func MakeInternalHTTPErr(err error) *HTTPErr

MakeInternalHTTPErr is a wrapper for MakeHTTPErr that passes in http.StatusInternalServerError, since we use that response quite often

func (*HTTPErr) Error

func (e *HTTPErr) Error() string

HTTPErr.Error is simply a wrapper around the inner error's Error() method with a nil check

type JSONErr

type JSONErr struct {
	Code int    `json:"code"`
	Text string `json:"text"`
}

JSONErr provides a common error struct for JSON

Jump to

Keyboard shortcuts

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