types: Use ErrorCode in ErrorResponse.
Using ErrorCode instead of int64 in the ErrorResponse type removes the burden of type conversion from calling code.
This commit is contained in:
parent
8303aa8536
commit
6d78e16b23
@ -1,3 +1,3 @@
|
|||||||
module github.com/decred/vspd/types
|
module github.com/decred/vspd/types/v2
|
||||||
|
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
// Copyright (c) 2020-2022 The Decred developers
|
// Copyright (c) 2020-2023 The Decred developers
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
type ErrorResponse struct {
|
type ErrorResponse struct {
|
||||||
Code int64 `json:"code"`
|
Code ErrorCode `json:"code"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2022 The Decred developers
|
// Copyright (c) 2022-2023 The Decred developers
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
@ -18,12 +18,12 @@ func TestAPIErrorAs(t *testing.T) {
|
|||||||
expectedMessage string
|
expectedMessage string
|
||||||
}{
|
}{
|
||||||
"BadRequest error": {
|
"BadRequest error": {
|
||||||
apiError: ErrorResponse{Message: "something went wrong", Code: int64(ErrBadRequest)},
|
apiError: ErrorResponse{Message: "something went wrong", Code: ErrBadRequest},
|
||||||
expectedKind: ErrBadRequest,
|
expectedKind: ErrBadRequest,
|
||||||
expectedMessage: "something went wrong",
|
expectedMessage: "something went wrong",
|
||||||
},
|
},
|
||||||
"Unknown error": {
|
"Unknown error": {
|
||||||
apiError: ErrorResponse{Message: "something went wrong again", Code: int64(999)},
|
apiError: ErrorResponse{Message: "something went wrong again", Code: 999},
|
||||||
expectedKind: 999,
|
expectedKind: 999,
|
||||||
expectedMessage: "something went wrong again",
|
expectedMessage: "something went wrong again",
|
||||||
},
|
},
|
||||||
@ -38,7 +38,7 @@ func TestAPIErrorAs(t *testing.T) {
|
|||||||
t.Fatalf("unable to unwrap error")
|
t.Fatalf("unable to unwrap error")
|
||||||
}
|
}
|
||||||
|
|
||||||
if parsedError.Code != int64(test.expectedKind) {
|
if parsedError.Code != test.expectedKind {
|
||||||
t.Fatalf("error was wrong kind. expected: %d actual %d",
|
t.Fatalf("error was wrong kind. expected: %d actual %d",
|
||||||
test.expectedKind, parsedError.Code)
|
test.expectedKind, parsedError.Code)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user