errors

package
v0.0.0-...-f9ba299 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2014 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package errors provides error types returned in CF SSL.

1. Type Error is intended for errors produced by CF SSL packages. It formats to a json object that consists of an error message and a 4-digit code for error reasoning.

Example: {"code":1002, "message": "Failed to decode certificate"}

The index of codes are listed below:

1XXX: CertificateError
    1000: Unknown
    1001: ReadFailed
    1002: DecodeFailed
    1003: ParseFailed
    1100: SelfSigned
    12XX: VerifyFailed
        121X: CertificateInvalid
            1210: NotAuthorizedToSign
            1211: Expired
            1212: CANotAuthorizedForThisName
            1213: TooManyIntermediates
            1214: IncompatibleUsage
        1220: UnknownAuthority
2XXX: PrivatekeyError
    2000: Unknown
    2001: ReadFailed
    2002: DecodeFailed
    2003: ParseFailed
    2100: Encrypted
    2200: NotRSA
    2300: KeyMismatch
3XXX: IntermediatesError
4XXX: RootError
5XXX: PolicyError
    5100: NoKeyUsages
    5200: InvalidPolicy
    5300: InvalidRequest
    6XXX: DialError

2. Type HttpError is intended for CF SSL API to consume. It contains a HTTP status code that will be read and returned by the API server.

Index

Constants

View Source
const (
	BundleExpiringBit      int = 1 << iota // 0x01
	BundleNotUbiquitousBit                 // 0x02
)

Warning code for a success

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category int

The error category as the most significant digit of the error code

const (
	Success            Category = 1000 * iota // 0XXX
	CertificateError                          // 1XXX
	PrivateKeyError                           // 2XXX
	IntermediatesError                        // 3XXX
	RootError                                 // 4XXX
	PolicyError                               // 5XXX
	DialError                                 // 6XXX
)

type Error

type Error struct {
	ErrorCode int    `json:"code"`
	Message   string `json:"message"`
}

Error is the error type usually returned by functions in CF SSL package. It contains a 4-digit error code where the most significant digit describes the category where the error occurred and the rest 3 digits describe the specific error reason.

func New

func New(category Category, reason Reason, err error) *Error

New returns an error that contains the given error and an error code derived from the given category, reason and the error. Currently, to avoid confusion, it is not allowed to create an error of category Success

func (*Error) Error

func (e *Error) Error() string

The error interface implementation, which formats to a JSON object string.

type HttpError

type HttpError struct {
	StatusCode int
	// contains filtered or unexported fields
}

HttpError is an augmented error with a HTTP status code.

func NewBadRequest

func NewBadRequest(err error) *HttpError

NewBadRequest creates a HttpError with the given error and error code 400.

func NewBadRequestMissingParameter

func NewBadRequestMissingParameter(s string) *HttpError

NewBadRequestMissingParameter returns a 400 HttpError as a required parameter is missing in the HTTP request.

func NewBadRequestString

func NewBadRequestString(s string) *HttpError

NewBadRequestString returns a HttpError with the supplied message and error code 400.

func NewBadRequestUnwantedParameter

func NewBadRequestUnwantedParameter(s string) *HttpError

NewBadRequestUnwantedParameter returns a 400 HttpError as a unnecessary parameter is present in the HTTP request.

func NewMethodNotAllowed

func NewMethodNotAllowed(method string) *HttpError

func (*HttpError) Error

func (e *HttpError) Error() string

The error interface implementation

type Reason

type Reason int

The error reason as the last 3 digits of the error code.

const (
	Unknown      Reason = iota // X000
	ReadFailed                 // X001
	DecodeFailed               // X002
	ParseFailed                // X003
)

Parsing errors

const (
	// Code 11XX
	SelfSigned Reason = 100 * (iota + 1)
	// Code 12XX
	// The least two significant digits of 12XX is determined as the actual x509 error is examined.
	VerifyFailed
	// Returned on bad certificate request
	BadRequest
)

Certificate non-parsing errors, must be specified along with CertificateError

const (
	Encrypted        Reason = 100 * (iota + 1) //21XX
	NotRSAOrECC                                //22XX
	KeyMismatch                                //23XX
	GenerationFailed                           //24XX
)

Private key non-parsing errors, must be specified with PrivateKeyError

const (
	NoKeyUsages    Reason = 100 * (iota + 1) // 51XX
	InvalidPolicy                            // 52XX
	InvalidRequest                           // 53XX
)

Policy non-parsing errors, must be specified along with PolicyError.

const (
	None Reason = iota
)

Non-specified error

Jump to

Keyboard shortcuts

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