Rename APIError to ErrorResponse. (#360)
Last commit before tagging v1.0.0 of the types module. The name ErrorResponse is consistent with all other response types.
This commit is contained in:
parent
ed1fac1a2a
commit
6d872db60e
@ -9,7 +9,6 @@ linters:
|
|||||||
- durationcheck
|
- durationcheck
|
||||||
- errcheck
|
- errcheck
|
||||||
- errchkjson
|
- errchkjson
|
||||||
- errname
|
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- exportloopref
|
- exportloopref
|
||||||
- goconst
|
- goconst
|
||||||
|
|||||||
@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
type APIError struct {
|
type ErrorResponse struct {
|
||||||
Code int64 `json:"code"`
|
Code int64 `json:"code"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e APIError) Error() string { return e.Message }
|
func (e ErrorResponse) Error() string { return e.Message }
|
||||||
|
|
||||||
type VspInfoResponse struct {
|
type VspInfoResponse struct {
|
||||||
APIVersions []int64 `json:"apiversions"`
|
APIVersions []int64 `json:"apiversions"`
|
||||||
|
|||||||
@ -19,20 +19,20 @@ func TestAPIErrorAs(t *testing.T) {
|
|||||||
expectedMessage string
|
expectedMessage string
|
||||||
}{{
|
}{{
|
||||||
testName: "BadRequest error",
|
testName: "BadRequest error",
|
||||||
apiError: APIError{Message: "something went wrong", Code: int64(ErrBadRequest)},
|
apiError: ErrorResponse{Message: "something went wrong", Code: int64(ErrBadRequest)},
|
||||||
expectedKind: ErrBadRequest,
|
expectedKind: ErrBadRequest,
|
||||||
expectedMessage: "something went wrong",
|
expectedMessage: "something went wrong",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "Unknown error",
|
testName: "Unknown error",
|
||||||
apiError: APIError{Message: "something went wrong again", Code: int64(999)},
|
apiError: ErrorResponse{Message: "something went wrong again", Code: int64(999)},
|
||||||
expectedKind: 999,
|
expectedKind: 999,
|
||||||
expectedMessage: "something went wrong again",
|
expectedMessage: "something went wrong again",
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
// Ensure APIError can be unwrapped from error.
|
// Ensure APIError can be unwrapped from error.
|
||||||
var parsedError APIError
|
var parsedError ErrorResponse
|
||||||
if !errors.As(test.apiError, &parsedError) {
|
if !errors.As(test.apiError, &parsedError) {
|
||||||
t.Errorf("%s: unable to unwrap error", test.testName)
|
t.Errorf("%s: unable to unwrap error", test.testName)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -302,7 +302,7 @@ func (s *Server) sendError(e types.ErrorCode, c *gin.Context) {
|
|||||||
func (s *Server) sendErrorWithMsg(msg string, e types.ErrorCode, c *gin.Context) {
|
func (s *Server) sendErrorWithMsg(msg string, e types.ErrorCode, c *gin.Context) {
|
||||||
status := e.HTTPStatus()
|
status := e.HTTPStatus()
|
||||||
|
|
||||||
resp := types.APIError{
|
resp := types.ErrorResponse{
|
||||||
Code: int64(e),
|
Code: int64(e),
|
||||||
Message: msg,
|
Message: msg,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user