2015-08-10 17:27:25 +00:00
|
|
|
package logical
|
|
|
|
|
2018-07-11 19:45:09 +00:00
|
|
|
import "errors"
|
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrUnsupportedOperation is returned if the operation is not supported
|
|
|
|
// by the logical backend.
|
|
|
|
ErrUnsupportedOperation = errors.New("unsupported operation")
|
|
|
|
|
|
|
|
// ErrUnsupportedPath is returned if the path is not supported
|
|
|
|
// by the logical backend.
|
|
|
|
ErrUnsupportedPath = errors.New("unsupported path")
|
|
|
|
|
|
|
|
// ErrInvalidRequest is returned if the request is invalid
|
|
|
|
ErrInvalidRequest = errors.New("invalid request")
|
|
|
|
|
|
|
|
// ErrPermissionDenied is returned if the client is not authorized
|
|
|
|
ErrPermissionDenied = errors.New("permission denied")
|
|
|
|
|
|
|
|
// ErrMultiAuthzPending is returned if the the request needs more
|
|
|
|
// authorizations
|
|
|
|
ErrMultiAuthzPending = errors.New("request needs further approval")
|
|
|
|
)
|
|
|
|
|
2015-08-10 17:27:25 +00:00
|
|
|
type HTTPCodedError interface {
|
2016-08-19 20:48:32 +00:00
|
|
|
Error() string
|
|
|
|
Code() int
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 20:29:59 +00:00
|
|
|
func CodedError(status int, msg string) HTTPCodedError {
|
|
|
|
return &codedError{
|
|
|
|
Status: status,
|
|
|
|
Message: msg,
|
|
|
|
}
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 20:08:44 +00:00
|
|
|
var _ HTTPCodedError = (*codedError)(nil)
|
|
|
|
|
2015-08-10 17:27:25 +00:00
|
|
|
type codedError struct {
|
2017-10-19 20:29:59 +00:00
|
|
|
Status int
|
|
|
|
Message string
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *codedError) Error() string {
|
2017-10-19 20:29:59 +00:00
|
|
|
return e.Message
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *codedError) Code() int {
|
2017-10-19 20:29:59 +00:00
|
|
|
return e.Status
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
2017-02-16 20:15:02 +00:00
|
|
|
|
|
|
|
// Struct to identify user input errors. This is helpful in responding the
|
|
|
|
// appropriate status codes to clients from the HTTP endpoints.
|
|
|
|
type StatusBadRequest struct {
|
|
|
|
Err string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implementing error interface
|
|
|
|
func (s *StatusBadRequest) Error() string {
|
|
|
|
return s.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a new type declared to not cause potential compatibility problems if
|
2017-10-19 20:29:59 +00:00
|
|
|
// the logic around the CodedError changes; in particular for logical request
|
|
|
|
// paths it is basically ignored, and changing that behavior might cause
|
|
|
|
// unforseen issues.
|
2017-02-16 20:15:02 +00:00
|
|
|
type ReplicationCodedError struct {
|
|
|
|
Msg string
|
|
|
|
Code int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReplicationCodedError) Error() string {
|
|
|
|
return r.Msg
|
|
|
|
}
|