errors

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: MIT Imports: 5 Imported by: 5

README

Errors

A simple utility for error handling in go/echo microservices

Usage

Echo

import (
    "github.com/labstack/echo/v4"
    errorsecho "gitlab.com/thegalabs/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

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

func (e Code) GetResponse() interface{}

GetResponse returns the same object

func (Code) GetStatusCode

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

func DefaultTranslator(err error) HTTPError

DefaultTranslator handles types from echo and validator

type NoResponse

type NoResponse int

NoResponse is a response with no body

func (NoResponse) Error

func (e NoResponse) Error() string

Error returns a string

func (NoResponse) GetResponse

func (e NoResponse) GetResponse() interface{}

GetResponse returns the same object

func (NoResponse) GetStatusCode

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

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

type Translator func(error) HTTPError

Translator translates a function into an HTTPError or nil

type ValidationErrors

type ValidationErrors validator.ValidationErrors

ValidationErrors is a wrapper around validator.ValidationErrors

func (ValidationErrors) Error

func (ve ValidationErrors) Error() string

Error returns the validator.ValidationErrors's error

func (ValidationErrors) GetResponse

func (ve ValidationErrors) GetResponse() interface{}

GetResponse returns the error detail

func (ValidationErrors) GetStatusCode

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