Documentation ¶
Index ¶
- Constants
- func ApplyOptions(err error, opts ...interface{}) error
- func BadRequest(format string, args ...interface{}) error
- func BadRequestErr(err error, format string, args ...interface{}) error
- func Errorf(code int, format string, args ...interface{}) error
- func Forbidden(format string, args ...interface{}) error
- func ForbiddenErr(err error, format string, args ...interface{}) error
- func InternalServer(format string, args ...interface{}) error
- func InternalServerErr(err error, opts ...Option) error
- func New(status int, format string, args ...interface{}) error
- func NewErr(status int, err error, opts ...Option) error
- func NewError(status int, err error, format string, args ...interface{}) error
- func NotFound(format string, args ...interface{}) error
- func NotFoundErr(err error, opts ...Option) error
- func NotImplemented(format string, args ...interface{}) error
- func NotImplementedErr(err error, opts ...Option) error
- func StatusCodeError(code int, e error, opts ...Option) error
- func Unauthorized(format string, args ...interface{}) error
- func UnauthorizedErr(err error, opts ...Option) error
- func UnexpectedErr(code int, err error, opts ...Option) error
- func Wrap(status int, e error, m string, args ...interface{}) error
- func Wrapf(status int, e error, format string, args ...interface{}) error
- type Error
- type ErrorResponse
- type Messenger
- type Option
Constants ¶
const ( // BadRequestDefaultMsg 400 default msg BadRequestDefaultMsg = "The request could not be completed; malformed or missing data. " + seeLogs 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 )
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
ApplyOptions applies the given options to the error if is the type *Error. TODO(mariano): try to get rid of this.
func BadRequest ¶
BadRequest creates a 400 error with the given format and arguments.
func BadRequestErr ¶
BadRequestErr returns an 400 error with the given error.
func ForbiddenErr ¶
ForbiddenErr returns an 403 error with the given error.
func InternalServer ¶
InternalServer creates a 500 error with the given format and arguments.
func InternalServerErr ¶
InternalServerErr returns a 500 error with the given error.
func NewErr ¶
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
NewError creates a new http error with the given error and message.
func NotFoundErr ¶
NotFoundErr returns an 404 error with the given error.
func NotImplemented ¶
NotImplemented creates a 501 error with the given format and arguments.
func NotImplementedErr ¶
NotImplementedErr returns a 501 error with the given error.
func StatusCodeError ¶
StatusCodeError selects the proper error based on the status code.
func Unauthorized ¶
Unauthorized creates a 401 error with the given format and arguments.
func UnauthorizedErr ¶
UnauthorizedErr returns an 401 error with the given error.
func UnexpectedErr ¶
UnexpectedErr will be used when the certificate authority makes an outgoing request and receives an unhandled status code.
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) MarshalJSON ¶
MarshalJSON implements json.Marshaller interface for the Error struct.
func (*Error) StatusCode ¶
StatusCode implements the StatusCoder interface and returns the HTTP response code.
func (*Error) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface for the Error struct.
type ErrorResponse ¶
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 ¶
Option modifies the Error type.
func WithKeyVal ¶
WithKeyVal returns an Option that adds the given key-value pair to the Error details. This is helpful for debugging errors.
func WithMessage ¶
WithMessage returns an Option that modifies the error by overwriting the message only if it is empty.