2017-08-02 12:57:58 +05:30
|
|
|
package api
|
|
|
|
|
|
2018-03-21 20:08:27 +05:30
|
|
|
// HTTPError contains an error code and corresponding text which briefly
|
|
|
|
|
// describes the error in short.
|
2017-08-10 18:11:16 +05:30
|
|
|
type HTTPError struct {
|
2018-06-06 12:43:19 +05:30
|
|
|
Code int `json:"code"`
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
Fields map[string]string `json:"fields,omitempty"`
|
2018-03-21 20:08:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ErrorResp is an error response which may contain one or more error responses
|
|
|
|
|
type ErrorResp struct {
|
|
|
|
|
Errors []HTTPError `json:"errors"`
|
2017-08-02 12:57:58 +05:30
|
|
|
}
|
2017-11-14 16:36:39 +05:30
|
|
|
|
|
|
|
|
// ErrorCode represents API Error code Type
|
|
|
|
|
type ErrorCode uint16
|
|
|
|
|
|
|
|
|
|
const (
|
2018-03-21 20:08:27 +05:30
|
|
|
// ErrCodeGeneric represents generic error code for API responses
|
2018-03-22 14:44:26 +05:30
|
|
|
ErrCodeGeneric ErrorCode = iota + 1
|
2018-06-05 11:00:46 +05:30
|
|
|
// ErrTxnStepFailed represents failure of a txn step
|
|
|
|
|
ErrTxnStepFailed
|
2017-11-14 16:36:39 +05:30
|
|
|
)
|
2018-03-21 20:08:27 +05:30
|
|
|
|
|
|
|
|
// ErrorCodeMap maps error code to it's textual message
|
|
|
|
|
var ErrorCodeMap = map[ErrorCode]string{
|
2018-06-05 11:00:46 +05:30
|
|
|
ErrCodeGeneric: "generic error",
|
|
|
|
|
ErrTxnStepFailed: "a txn step failed",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ErrorResponse is an interface that types can implement on custom errors.
|
|
|
|
|
type ErrorResponse interface {
|
|
|
|
|
error
|
|
|
|
|
// Response returns the error response to be returned to client.
|
|
|
|
|
Response() ErrorResp
|
|
|
|
|
// Status returns the HTTP status code to be returned to client.
|
|
|
|
|
Status() int
|
2018-03-21 20:08:27 +05:30
|
|
|
}
|