Skip to content

Commit 20a74f5

Browse files
committed
chore: remove case used in investigating http.Error and add test of http.Error.Error() response.
1 parent af74d7a commit 20a74f5

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

api/http/error.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ func (e *Error) Error() string {
2727
return e.Err.Error()
2828
case e.Code != "" && e.Message != "":
2929
return fmt.Sprintf("%s: %s", e.Code, e.Message)
30-
case e.Message != "":
31-
return e.Message
3230
default:
3331
return "Unexpected status code " + strconv.Itoa(e.StatusCode)
3432
}

api/http/error_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package http
66

77
import (
8+
"fmt"
89
"github.com/stretchr/testify/assert"
910
ihttp "net/http"
1011

@@ -51,3 +52,30 @@ func TestWriteErrorHeaderToString(t *testing.T) {
5152
assert.NotContains(t, filterString, "Content-Type: application/json")
5253
assert.NotContains(t, filterString, "Retry-After: 2044")
5354
}
55+
56+
func TestErrorIfaceError(t *testing.T) {
57+
tests := []struct {
58+
statusCode int
59+
err error
60+
code string
61+
message string
62+
expected string
63+
}{
64+
{statusCode: 418, err: fmt.Errorf("original test message"), code: "", message: "", expected: "original test message"},
65+
{statusCode: 418, err: fmt.Errorf("original test message"), code: "bad request", message: "is this a teapot?", expected: "original test message"},
66+
{statusCode: 418, err: nil, code: "bad request", message: "is this a teapot?", expected: "bad request: is this a teapot?"},
67+
{statusCode: 418, err: nil, code: "I'm a teapot", message: "", expected: "Unexpected status code 418"},
68+
}
69+
70+
for _, test := range tests {
71+
err := Error{
72+
StatusCode: test.statusCode,
73+
Code: test.code,
74+
Message: test.message,
75+
Err: test.err,
76+
RetryAfter: 0,
77+
Header: ihttp.Header{},
78+
}
79+
assert.Equal(t, test.expected, err.Error())
80+
}
81+
}

0 commit comments

Comments
 (0)