errors

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: MIT Imports: 5 Imported by: 3

README

Errors

A simple utility for error handling in go/echo microservices

Usage

Echo

import (
    "github.com/labstack/echo/v4"
    errorsecho "gitlab.com/getiota/go/errors/echo"
)

e := echo.New()
...
e.HTTPErrorHandler = errorsecho.DefaultHandler()

Documentation

Overview

Package errors centralizes http error creation

Index

Constants

This section is empty.

Variables

View Source
var Is = errors.Is

Is is a drop in replacement for the standard errors package

View Source
var New = errors.New

New is a drop in replacement for the standard errors package

Functions

func Detail added in v0.2.1

func Detail(format string, args ...interface{}) error

Detail generates a default error response with the detail set

Types

type Code

type Code string

Code is to make it easier to return a 400

func (Code) Error

func (e Code) Error() string

func (Code) GetResponse added in v0.1.2

func (e Code) GetResponse() interface{}

GetResponse returns the same object

func (Code) GetStatusCode added in v0.1.2

func (e Code) GetStatusCode() int

GetStatusCode returns the status code

type HTTPError

type HTTPError interface {
	GetStatusCode() int
	GetResponse() interface{}
}

HTTPError is an interface for structured errors

func DefaultTranslator added in v0.1.2

func DefaultTranslator(err error) HTTPError

DefaultTranslator handles types from echo and validator

type NoResponse added in v0.1.2

type NoResponse int

NoResponse is a response with no body

func (NoResponse) Error added in v0.1.2

func (e NoResponse) Error() string

Error returns a string

func (NoResponse) GetResponse added in v0.1.2

func (e NoResponse) GetResponse() interface{}

GetResponse returns the same object

func (NoResponse) GetStatusCode added in v0.1.2

func (e NoResponse) GetStatusCode() int

GetStatusCode returns the status code

type Response

type Response struct {
	StatusCode int    `json:"-"`
	Code       string `json:"code,omitempty"`
	Detail     string `json:"detail,omitempty"`
}

Response is the default structure of an error response

func (Response) Error

func (e Response) Error() string

func (Response) GetResponse added in v0.1.1

func (e Response) GetResponse() interface{}

GetResponse returns the same object

func (Response) GetStatusCode

func (e Response) GetStatusCode() int

GetStatusCode returns the status code

type Translator added in v0.1.2

type Translator func(error) HTTPError

Translator translates a function into an HTTPError or nil

type ValidationErrors added in v0.1.2

type ValidationErrors validator.ValidationErrors

ValidationErrors is a wrapper around validator.ValidationErrors

func (ValidationErrors) Error added in v0.1.2

func (ve ValidationErrors) Error() string

Error returns the validator.ValidationErrors's error

func (ValidationErrors) GetResponse added in v0.1.2

func (ve ValidationErrors) GetResponse() interface{}

GetResponse returns the error detail

func (ValidationErrors) GetStatusCode added in v0.1.2

func (ve ValidationErrors) GetStatusCode() int

GetStatusCode returns a bad request

Directories

Path Synopsis
Package echo provides a default translator for the echo server
Package echo provides a default translator for the echo server

Jump to

Keyboard shortcuts

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