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:
Jamie Holdstock 2022-11-22 17:09:06 +08:00 committed by GitHub
parent ed1fac1a2a
commit 6d872db60e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 7 deletions

View File

@ -9,7 +9,6 @@ linters:
- durationcheck
- errcheck
- errchkjson
- errname
- exhaustive
- exportloopref
- goconst

View File

@ -4,12 +4,12 @@
package types
type APIError struct {
type ErrorResponse struct {
Code int64 `json:"code"`
Message string `json:"message"`
}
func (e APIError) Error() string { return e.Message }
func (e ErrorResponse) Error() string { return e.Message }
type VspInfoResponse struct {
APIVersions []int64 `json:"apiversions"`

View File

@ -19,20 +19,20 @@ func TestAPIErrorAs(t *testing.T) {
expectedMessage string
}{{
testName: "BadRequest error",
apiError: APIError{Message: "something went wrong", Code: int64(ErrBadRequest)},
apiError: ErrorResponse{Message: "something went wrong", Code: int64(ErrBadRequest)},
expectedKind: ErrBadRequest,
expectedMessage: "something went wrong",
},
{
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,
expectedMessage: "something went wrong again",
}}
for _, test := range tests {
// Ensure APIError can be unwrapped from error.
var parsedError APIError
var parsedError ErrorResponse
if !errors.As(test.apiError, &parsedError) {
t.Errorf("%s: unable to unwrap error", test.testName)
continue

View File

@ -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) {
status := e.HTTPStatus()
resp := types.APIError{
resp := types.ErrorResponse{
Code: int64(e),
Message: msg,
}