berrors

package module
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2020 License: GPL-3.0 Imports: 9 Imported by: 0

README

backend-errors

backend-errors is a package developed and used by alexandrio.
It is made so that every micro services can use the same errors methods.

Documentation

Documentation is accessible on godoc.

Tests

Unit tests can be run using:

go test -v -cover ./...

Documentation

Overview

backend-errors is a package developed and used by alexandrio. It is made so that every micro service can use the same errors methods.

Index

Constants

This section is empty.

Variables

View Source
var ErrorTypes = map[ErrorType]string{
	Email:    "The email given is not correct",
	Required: "The field is required",
	Login:    "The login and password does not match",
}

Functions

func BadInputJSON

func BadInputJSON(name string, reason string) []byte

BadInputJSON is simply a call to BadInputsJSON to create a single bad input error. It returns the JSON of the struct BadInput in []byte.

func BadInputJSONFromType

func BadInputJSONFromType(name string, errorType string) []byte

BadInputJSONFromType is simply a call to BadInputsJSONFromType to create a single bad input error. It returns the JSON of the struct BadInput in []byte.

func BadInputsJSON

func BadInputsJSON(fields map[string]string) []byte

BadInputsJSON creates the error JSON using the struct BadInput. The key of the map given correspond to the Name and the value to the Reason. It returns the JSON in []byte.

func BadInputsJSONFromType

func BadInputsJSONFromType(fields map[string]string) []byte

BadInputsJSONFromType create a BadInput JSON from a key and a value corresponding to an ErrorType. It replace the Value with the defined string corresponding to the ErrorType. It returns the JSON in []byte.

func GetJSONFieldName

func GetJSONFieldName(object interface{}, fieldName string) (string, error)

GetJSONFieldName is used to get the json tag of a given field in a struct

func InternalServerError

func InternalServerError(ctx *fiber.Ctx, err error)

InternalServerError set a 500 http error and log the error.

func ParseBodyJSON

func ParseBodyJSON(ctx *fiber.Ctx, object interface{}) bool

ParseBodyJSON parse and validate a body contained in the fiber context to the given object If an error occur, the correct http error is called and false is returned The validator errors messages are using BadInputsJSONFromType

Types

type BadInput

type BadInput struct {
	Fields []field `json:"fields"`
}

type ErrorType

type ErrorType string
const (
	Email    ErrorType = "email"
	Required ErrorType = "required"
	Login    ErrorType = "login"
)

type KafkaErrorMessage added in v1.2.6

type KafkaErrorMessage struct {
	Code    int    `json:"code"`
	Content []byte `json:"content"`
}

Jump to

Keyboard shortcuts

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