2015-08-10 17:27:25 +00:00
|
|
|
package logical
|
|
|
|
|
|
|
|
type HTTPCodedError interface {
|
2016-08-19 20:48:32 +00:00
|
|
|
Error() string
|
|
|
|
Code() int
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func CodedError(c int, s string) HTTPCodedError {
|
2016-08-19 20:48:32 +00:00
|
|
|
return &codedError{s, c}
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type codedError struct {
|
2016-08-19 20:48:32 +00:00
|
|
|
s string
|
|
|
|
code int
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *codedError) Error() string {
|
2016-08-19 20:48:32 +00:00
|
|
|
return e.s
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *codedError) Code() int {
|
2016-08-19 20:48:32 +00:00
|
|
|
return e.code
|
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
|
|
|
|
// the logic around the HTTPCodedError interface changes; in particular for
|
|
|
|
// logical request paths it is basically ignored, and changing that behavior
|
|
|
|
// might cause unforseen issues.
|
|
|
|
type ReplicationCodedError struct {
|
|
|
|
Msg string
|
|
|
|
Code int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReplicationCodedError) Error() string {
|
|
|
|
return r.Msg
|
|
|
|
}
|