distribution: github.com/docker/distribution/registry/api/errcode Index | Files

package errcode

import "github.com/docker/distribution/registry/api/errcode"

Index

Package Files

errors.go handler.go register.go

Variables

var (
    ErrorCodeUnknown = Register("errcode", ErrorDescriptor{
        Value:   "UNKNOWN",
        Message: "unknown error",
        Description: `Generic error returned when the error does not have an
			                                            API classification.`,
        HTTPStatusCode: http.StatusInternalServerError,
    })

    ErrorCodeUnsupported = Register("errcode", ErrorDescriptor{
        Value:   "UNSUPPORTED",
        Message: "The operation is unsupported.",
        Description: `The operation was unsupported due to a missing
		implementation or invalid set of parameters.`,
        HTTPStatusCode: http.StatusMethodNotAllowed,
    })

    ErrorCodeUnauthorized = Register("errcode", ErrorDescriptor{
        Value:       "UNAUTHORIZED",
        Message:     "authentication required",
        Description: "" /* 174 byte string literal not displayed */,

        HTTPStatusCode: http.StatusUnauthorized,
    })

    ErrorCodeDenied = Register("errcode", ErrorDescriptor{
        Value:   "DENIED",
        Message: "requested access to the resource is denied",
        Description: `The access controller denied access for the
		operation on a resource.`,
        HTTPStatusCode: http.StatusForbidden,
    })

    ErrorCodeUnavailable = Register("errcode", ErrorDescriptor{
        Value:          "UNAVAILABLE",
        Message:        "service unavailable",
        Description:    "Returned when a service is not available",
        HTTPStatusCode: http.StatusServiceUnavailable,
    })

    ErrorCodeTooManyRequests = Register("errcode", ErrorDescriptor{
        Value:   "TOOMANYREQUESTS",
        Message: "too many requests",
        Description: `Returned when a client attempts to contact a
		service too many times`,
        HTTPStatusCode: http.StatusTooManyRequests,
    })
)

func GetGroupNames Uses

func GetGroupNames() []string

GetGroupNames returns the list of Error group names that are registered

func ServeJSON Uses

func ServeJSON(w http.ResponseWriter, err error) error

ServeJSON attempts to serve the errcode in a JSON envelope. It marshals err and sets the content-type header to 'application/json'. It will handle ErrorCoder and Errors, and if necessary will create an envelope.

type Error Uses

type Error struct {
    Code    ErrorCode   `json:"code"`
    Message string      `json:"message"`
    Detail  interface{} `json:"detail,omitempty"`
}

Error provides a wrapper around ErrorCode with extra Details provided.

func (Error) Error Uses

func (e Error) Error() string

Error returns a human readable representation of the error.

func (Error) ErrorCode Uses

func (e Error) ErrorCode() ErrorCode

ErrorCode returns the ID/Value of this Error

func (Error) WithArgs Uses

func (e Error) WithArgs(args ...interface{}) Error

WithArgs uses the passed-in list of interface{} as the substitution variables in the Error's Message string, but returns a new Error

func (Error) WithDetail Uses

func (e Error) WithDetail(detail interface{}) Error

WithDetail will return a new Error, based on the current one, but with some Detail info added

type ErrorCode Uses

type ErrorCode int

ErrorCode represents the error type. The errors are serialized via strings and the integer format may change and should *never* be exported.

func ParseErrorCode Uses

func ParseErrorCode(value string) ErrorCode

ParseErrorCode returns the value by the string error code. `ErrorCodeUnknown` will be returned if the error is not known.

func Register Uses

func Register(group string, descriptor ErrorDescriptor) ErrorCode

Register will make the passed-in error known to the environment and return a new ErrorCode

func (ErrorCode) Descriptor Uses

func (ec ErrorCode) Descriptor() ErrorDescriptor

Descriptor returns the descriptor for the error code.

func (ErrorCode) Error Uses

func (ec ErrorCode) Error() string

Error returns the ID/Value

func (ErrorCode) ErrorCode Uses

func (ec ErrorCode) ErrorCode() ErrorCode

ErrorCode just returns itself

func (ErrorCode) MarshalText Uses

func (ec ErrorCode) MarshalText() (text []byte, err error)

MarshalText encodes the receiver into UTF-8-encoded text and returns the result.

func (ErrorCode) Message Uses

func (ec ErrorCode) Message() string

Message returned the human-readable error message for this error code.

func (ErrorCode) String Uses

func (ec ErrorCode) String() string

String returns the canonical identifier for this error code.

func (*ErrorCode) UnmarshalText Uses

func (ec *ErrorCode) UnmarshalText(text []byte) error

UnmarshalText decodes the form generated by MarshalText.

func (ErrorCode) WithArgs Uses

func (ec ErrorCode) WithArgs(args ...interface{}) Error

WithArgs creates a new Error struct and sets the Args slice

func (ErrorCode) WithDetail Uses

func (ec ErrorCode) WithDetail(detail interface{}) Error

WithDetail creates a new Error struct based on the passed-in info and set the Detail property appropriately

func (ErrorCode) WithMessage Uses

func (ec ErrorCode) WithMessage(message string) Error

WithMessage creates a new Error struct based on the passed-in info and overrides the Message property.

type ErrorCoder Uses

type ErrorCoder interface {
    ErrorCode() ErrorCode
}

ErrorCoder is the base interface for ErrorCode and Error allowing users of each to just call ErrorCode to get the real ID of each

type ErrorDescriptor Uses

type ErrorDescriptor struct {
    // Code is the error code that this descriptor describes.
    Code ErrorCode

    // Value provides a unique, string key, often captilized with
    // underscores, to identify the error code. This value is used as the
    // keyed value when serializing api errors.
    Value string

    // Message is a short, human readable decription of the error condition
    // included in API responses.
    Message string

    // Description provides a complete account of the errors purpose, suitable
    // for use in documentation.
    Description string

    // HTTPStatusCode provides the http status code that is associated with
    // this error condition.
    HTTPStatusCode int
}

ErrorDescriptor provides relevant information about a given error code.

func GetErrorAllDescriptors Uses

func GetErrorAllDescriptors() []ErrorDescriptor

GetErrorAllDescriptors returns a slice of all ErrorDescriptors that are registered, irrespective of what group they're in

func GetErrorCodeGroup Uses

func GetErrorCodeGroup(name string) []ErrorDescriptor

GetErrorCodeGroup returns the named group of error descriptors

type Errors Uses

type Errors []error

Errors provides the envelope for multiple errors and a few sugar methods for use within the application.

func (Errors) Error Uses

func (errs Errors) Error() string

func (Errors) Len Uses

func (errs Errors) Len() int

Len returns the current number of errors.

func (Errors) MarshalJSON Uses

func (errs Errors) MarshalJSON() ([]byte, error)

MarshalJSON converts slice of error, ErrorCode or Error into a slice of Error - then serializes

func (*Errors) UnmarshalJSON Uses

func (errs *Errors) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes []Error and then converts it into slice of Error or ErrorCode

Package errcode imports 6 packages (graph) and is imported by 1687 packages. Updated 2019-04-04. Refresh now. Tools for package owners.