errors: github.com/aodin/errors Index | Files

package errors

import "github.com/aodin/errors"

Package errors provides a robust errors type which implements the built-in error interface. It includes the following:

* Code, an int field for integer error codes such as HTTP status

* Meta, a []string field for high-level errors

* Fields, a map[string]string field for named errors

It supports both JSON and XML marshaling.

Index

Package Files

errors.go

type Error Uses

type Error struct {
    Code   int               `json:"code,omitempty"`
    Meta   []string          `json:"meta"`
    Fields map[string]string `json:"fields"`
}

Error is an error structure with meta and field-specific errors

func BadRequest Uses

func BadRequest() *Error

BadRequest creates an error with a 400 status code

func Message Uses

func Message(msg string, args ...interface{}) *Error

Message creates a new *Error with the given message

func Meta Uses

func Meta(code int, msg string, args ...interface{}) *Error

Meta returns an error with a pre-set meta error

func New Uses

func New() *Error

New creates a new empty error

func (*Error) Add Uses

func (er *Error) Add(msg string, args ...interface{})

Add is an alias for AddMeta

func (*Error) AddMeta Uses

func (er *Error) AddMeta(msg string, args ...interface{})

AddMeta appends a meta error

func (Error) Error Uses

func (er Error) Error() string

Error implements the error interface

func (Error) Exists Uses

func (er Error) Exists() bool

Exists returns true if there are either meta or field errors

func (Error) InField Uses

func (er Error) InField(field string) bool

InField returns true if the given field has an error

func (Error) IsEmpty Uses

func (er Error) IsEmpty() bool

IsEmpty return false if there are no meta or field errors

func (Error) MarshalXML Uses

func (er Error) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements a custom marshaler because Errors has a map

func (*Error) Set Uses

func (er *Error) Set(field, msg string, args ...interface{})

Set is an alias for SetField

func (*Error) SetField Uses

func (er *Error) SetField(field, msg string, args ...interface{})

SetField sets the error message for the field. Mutiple calls will overwrite previous messages for that field.

Package errors imports 4 packages (graph) and is imported by 3 packages. Updated 2016-07-23. Refresh now. Tools for package owners.