1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENCE file for details.
10
// ErrorCode holds the class of an error in machine-readable format.
11
// It is also an error in its own right.
14
func (code ErrorCode) Error() string {
18
func (code ErrorCode) ErrorCode() ErrorCode {
23
ErrNotFound ErrorCode = "not found"
24
ErrForbidden ErrorCode = "forbidden"
25
ErrBadRequest ErrorCode = "bad request"
26
ErrUnauthorized ErrorCode = "unauthorized"
27
ErrAlreadyExists ErrorCode = "already exists"
28
ErrNoAdminCredsProvided ErrorCode = "no admin credentials provided"
29
ErrMethodNotAllowed ErrorCode = "method not allowed"
30
ErrServiceUnavailable ErrorCode = "service unavailable"
33
// Error represents an error - it is returned for any response that fails.
35
Message string `json:"message,omitempty"`
36
Code ErrorCode `json:"code,omitempty"`
39
// NewError returns a new *Error with the given error code
41
func NewError(code ErrorCode, f string, a ...interface{}) error {
43
Message: fmt.Sprintf(f, a...),
48
// Error implements error.Error.
49
func (e *Error) Error() string {
53
// ErrorCode holds the class of the error in machine readable format.
54
func (e *Error) ErrorCode() string {
58
// Cause implements errgo.Causer.Cause.
59
func (e *Error) Cause() error {