httperror

package module
v0.0.0-...-3b1d24b Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2017 License: MIT Imports: 5 Imported by: 0

README

httperror

GoDoc Go Report Card Build Status Coverage Status

Acoshift's HTTP error collection for Go

Documentation

Overview

Package httperror is the reusable http error collection

Index

Constants

This section is empty.

Variables

View Source
var (
	BadRequest          = newPreDefinedHTTPError(http.StatusBadRequest)
	Unauthorized        = newPreDefinedHTTPError(http.StatusUnauthorized)
	Forbidden           = newPreDefinedHTTPError(http.StatusForbidden)
	NotFound            = newPreDefinedHTTPError(http.StatusNotFound)
	MethodNotAllowed    = newPreDefinedHTTPError(http.StatusMethodNotAllowed)
	RequestTimeout      = newPreDefinedHTTPError(http.StatusRequestTimeout)
	Conflict            = newPreDefinedHTTPError(http.StatusConflict)
	Gone                = newPreDefinedHTTPError(http.StatusGone)
	InternalServerError = newPreDefinedHTTPError(http.StatusInternalServerError)
	NotImplemented      = newPreDefinedHTTPError(http.StatusNotImplemented)
)

Pre-defined errors

Functions

func BadRequestWith

func BadRequestWith(err error) error

BadRequestWith merges error with bad request

func ConflictWith

func ConflictWith(err error) error

ConflictWith merges error with conflict

func ForbiddenWith

func ForbiddenWith(err error) error

ForbiddenWith merges error with forbidden

func GRPC

func GRPC(err error) error

GRPC maps grpc error to http error

func GoneWith

func GoneWith(err error) error

GoneWith merges error with gone

func InternalServerErrorWith

func InternalServerErrorWith(err error) error

InternalServerErrorWith merges error with internal server error

func Merge

func Merge(err, other error) error

Merge an error with other error if one or both errors are Error type, result will be an Error if none is Error, result will be native go's error

func MethodNotAllowedWith

func MethodNotAllowedWith(err error) error

MethodNotAllowedWith merges error with method not allowed

func NewError

func NewError(status int, code string, message string) error

NewError creates new Error

func NewHTTPError

func NewHTTPError(status int, code string) error

NewHTTPError is the helper function for create http error

func NotFoundWith

func NotFoundWith(err error) error

NotFoundWith merges error with not found

func RequestTimeoutWith

func RequestTimeoutWith(err error) error

RequestTimeoutWith merges error with request timeout

func UnauthorizedWith

func UnauthorizedWith(err error) error

UnauthorizedWith merges error with unauthorized

Types

type CodeFunc

type CodeFunc func(int, error) error

CodeFunc is the error creator function pre-defined code

func NewWithCode

func NewWithCode(code string) CodeFunc

NewWithCode is the helper function for create CodeFunc

type Error

type Error struct {
	Status  int    `json:"status"`  // http status code
	Code    string `json:"code"`    // error code
	Message string `json:"message"` // error message
}

Error is the httperror's Error

func (Error) Clone

func (err Error) Clone() *Error

Clone error

func (*Error) Error

func (err *Error) Error() string

Error implements error interface

type Func

type Func func(error) error

Func is the error creator function

func New

func New(status int, code string) Func

New is the helper function for create Func

type StatusFunc

type StatusFunc func(string, error) error

StatusFunc is the error creator function pre-defined status

func NewWithStatus

func NewWithStatus(status int) StatusFunc

NewWithStatus is the helper function for create StatusFunc

Jump to

Keyboard shortcuts

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