fault

package
v0.0.0-...-77132cc Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Missing           = string("missing")
	MissingField      = string("missing_field")
	UnregisteredField = string("unregistered_field")
	Illegal           = string("illegal")
	Invalid           = string("invalid")
	AlreadyExists     = string("already_exists")
	Conflict          = string("conflict")
)

Some of the causes

Functions

This section is empty.

Types

type Cause

type Cause interface {
	Resource() string
	Field() string
	Code() string
	SetResource(string) Cause
	SetField(string) Cause
	SetCode(string) Cause
}

Cause interface

func For

func For(code string) Cause

For to create error

type Context

type Context interface {
	ID() string
	Status() int
	Message() string
	Causes() []Cause
	Error() string
	SetStatus(int) Context
	AddCause(...Cause) Context
	Json() []byte
	JsonString() string
}

Context interface

func Is

func Is(e error) (Context, bool)

Is to check if error is fault context

func New

func New(message string) Context

New creates fault error from string

func Wrap

func Wrap(err error) Context

Wrap creates fault error from error

type Fault

type Fault struct {
	FID      string  `json:"id"`
	FStatus  int     `json:"status"`
	FMessage string  `json:"message"`
	FCauses  []Cause `json:"causes"`
}

Fault struct

func (*Fault) AddCause

func (v *Fault) AddCause(s ...Cause) Context

AddCause error

func (*Fault) Causes

func (v *Fault) Causes() []Cause

Causes of the fault

func (*Fault) Error

func (v *Fault) Error() string

func (*Fault) ErrorOrNil

func (v *Fault) ErrorOrNil() error

ErrorOrNil returns a fault error only if there are errors

func (*Fault) ID

func (v *Fault) ID() string

ID of the fault

func (*Fault) Json

func (v *Fault) Json() []byte

Json to return json bytes of the error

func (*Fault) JsonString

func (v *Fault) JsonString() string

JsonString to return json string of the error

func (*Fault) Message

func (v *Fault) Message() string

Message of the fault

func (*Fault) SetStatus

func (v *Fault) SetStatus(s int) Context

SetStatus to set fault status

func (*Fault) Status

func (v *Fault) Status() int

Status return status code

type Formatter

type Formatter string

Template struct

func (Formatter) Fill

func (v Formatter) Fill(a ...interface{}) Context

type Reason

type Reason struct {
	RResource string `json:"resource,omitempty"`
	RField    string `json:"field,omitempty"`
	RCode     string `json:"code,omitempty"`
}

Reason struct

func (*Reason) Code

func (v *Reason) Code() string

Code to return code name

func (*Reason) Field

func (v *Reason) Field() string

Field to return field name

func (*Reason) Resource

func (v *Reason) Resource() string

Resource to return resource name

func (*Reason) SetCode

func (v *Reason) SetCode(s string) Cause

SetCode to set code

func (*Reason) SetField

func (v *Reason) SetField(s string) Cause

SetField to set field

func (*Reason) SetResource

func (v *Reason) SetResource(s string) Cause

SetResource to set resource

type Template

type Template interface {
	Fill(...interface{}) Context
}

Template interface

func Format

func Format(format string) Template

Format to compose failure reusable template

Jump to

Keyboard shortcuts

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