From 6d872db60e339547a9abf756fd25e5cfd05fded3 Mon Sep 17 00:00:00 2001 From: Jamie Holdstock Date: Tue, 22 Nov 2022 17:09:06 +0800 Subject: [PATCH] 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. --- .golangci.yml | 1 - types/types.go | 4 ++-- types/types_test.go | 6 +++--- webapi/webapi.go | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b199a34..2492e50 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,7 +9,6 @@ linters: - durationcheck - errcheck - errchkjson - - errname - exhaustive - exportloopref - goconst diff --git a/types/types.go b/types/types.go index 88ae2e2..3152637 100644 --- a/types/types.go +++ b/types/types.go @@ -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"` diff --git a/types/types_test.go b/types/types_test.go index d659ebc..45bb323 100644 --- a/types/types_test.go +++ b/types/types_test.go @@ -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 diff --git a/webapi/webapi.go b/webapi/webapi.go index 03f05fd..9498313 100644 --- a/webapi/webapi.go +++ b/webapi/webapi.go @@ -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, }