errs

package
v0.27.4 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: Apache-2.0 Imports: 6 Imported by: 4

Documentation

Index

Constants

View Source
const (

	// BadRequestDefaultMsg 400 default msg
	BadRequestDefaultMsg = "The request could not be completed; malformed or missing data. " + seeLogs
	// UnauthorizedDefaultMsg 401 default msg
	UnauthorizedDefaultMsg = "The request lacked necessary authorization to be completed. " + seeLogs
	// ForbiddenDefaultMsg 403 default msg
	ForbiddenDefaultMsg = "The request was forbidden by the certificate authority. " + seeLogs
	// NotFoundDefaultMsg 404 default msg
	NotFoundDefaultMsg = "The requested resource could not be found. " + seeLogs
	// InternalServerErrorDefaultMsg 500 default msg
	InternalServerErrorDefaultMsg = "The certificate authority encountered an Internal Server Error. " + seeLogs
	// NotImplementedDefaultMsg 501 default msg
	NotImplementedDefaultMsg = "The requested method is not implemented by the certificate authority. " + seeLogs
)
View Source
const (
	// BadRequestPrefix is the prefix added to the bad request messages that are
	// directly sent to the cli.
	BadRequestPrefix = "The request could not be completed: "

	// ForbiddenPrefix is the prefix added to the forbidden messates that are
	// sent to the cli.
	ForbiddenPrefix = "The request was forbidden by the certificate authority: "
)

Variables

This section is empty.

Functions

func ApplyOptions added in v0.18.1

func ApplyOptions(err error, opts ...interface{}) error

ApplyOptions applies the given options to the error if is the type *Error. TODO(mariano): try to get rid of this.

func BadRequest

func BadRequest(format string, args ...interface{}) error

BadRequest creates a 400 error with the given format and arguments.

func BadRequestErr

func BadRequestErr(err error, format string, args ...interface{}) error

BadRequestErr returns an 400 error with the given error.

func Errorf

func Errorf(code int, format string, args ...interface{}) error

Errorf creates a new error using the given format and status code.

func Forbidden

func Forbidden(format string, args ...interface{}) error

Forbidden creates a 403 error with the given format and arguments.

func ForbiddenErr

func ForbiddenErr(err error, format string, args ...interface{}) error

ForbiddenErr returns an 403 error with the given error.

func InternalServer

func InternalServer(format string, args ...interface{}) error

InternalServer creates a 500 error with the given format and arguments.

func InternalServerErr

func InternalServerErr(err error, opts ...Option) error

InternalServerErr returns a 500 error with the given error.

func New added in v0.18.1

func New(status int, format string, args ...interface{}) error

New creates a new http error with the given status and message.

func NewErr

func NewErr(status int, err error, opts ...Option) error

NewErr returns a new Error. If the given error implements the StatusCoder interface we will ignore the given status.

func NewError added in v0.18.1

func NewError(status int, err error, format string, args ...interface{}) error

NewError creates a new http error with the given error and message.

func NotFound

func NotFound(format string, args ...interface{}) error

NotFound creates a 404 error with the given format and arguments.

func NotFoundErr

func NotFoundErr(err error, opts ...Option) error

NotFoundErr returns an 404 error with the given error.

func NotImplemented

func NotImplemented(format string, args ...interface{}) error

NotImplemented creates a 501 error with the given format and arguments.

func NotImplementedErr

func NotImplementedErr(err error, opts ...Option) error

NotImplementedErr returns a 501 error with the given error.

func StatusCodeError

func StatusCodeError(code int, e error, opts ...Option) error

StatusCodeError selects the proper error based on the status code.

func Unauthorized

func Unauthorized(format string, args ...interface{}) error

Unauthorized creates a 401 error with the given format and arguments.

func UnauthorizedErr

func UnauthorizedErr(err error, opts ...Option) error

UnauthorizedErr returns an 401 error with the given error.

func UnexpectedErr

func UnexpectedErr(code int, err error, opts ...Option) error

UnexpectedErr will be used when the certificate authority makes an outgoing request and receives an unhandled status code.

func Wrap

func Wrap(status int, e error, m string, args ...interface{}) error

Wrap returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message. If err is nil, Wrap returns nil.

func Wrapf

func Wrapf(status int, e error, format string, args ...interface{}) error

Wrapf returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message. If err is nil, Wrap returns nil.

Types

type Error

type Error struct {
	Status    int
	Err       error
	Msg       string
	Details   map[string]interface{}
	RequestID string `json:"-"`
}

Error represents the CA API errors.

func (*Error) Cause

func (e *Error) Cause() error

Cause implements the errors.Causer interface and returns the original error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface and returns the error string.

func (*Error) Format

func (e *Error) Format(f fmt.State, c rune)

Format implements the fmt.Formatter interface.

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaller interface for the Error struct.

func (*Error) Message

func (e *Error) Message() string

Message returns a user friendly error, if one is set.

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode implements the StatusCoder interface and returns the HTTP response code.

func (*Error) UnmarshalJSON

func (e *Error) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface for the Error struct.

type ErrorResponse

type ErrorResponse struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
}

ErrorResponse represents an error in JSON format.

type Messenger

type Messenger interface {
	Message() string
}

Messenger is a friendly message interface that errors can implement.

type Option

type Option func(e *Error) error

Option modifies the Error type.

func WithKeyVal

func WithKeyVal(key string, val interface{}) Option

WithKeyVal returns an Option that adds the given key-value pair to the Error details. This is helpful for debugging errors.

func WithMessage

func WithMessage(format string, args ...interface{}) Option

WithMessage returns an Option that modifies the error by overwriting the message only if it is empty.

Jump to

Keyboard shortcuts

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