Skip to content

Commit 32da450

Browse files
authored
fix: dont change http status code in readEnvelope (#58)
1 parent a71d285 commit 32da450

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

errors.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,44 @@ func (e Error) Error() string {
3535
// NewError creates and returns a new instace of Error
3636
// with custom error metadata.
3737
func NewError(etype string, message string, data interface{}) error {
38-
err := Error{}
39-
err.Message = message
40-
err.ErrorType = etype
41-
err.Data = data
38+
var (
39+
code = http.StatusInternalServerError
40+
)
4241

4342
switch etype {
4443
case GeneralError:
45-
err.Code = http.StatusInternalServerError
44+
code = http.StatusInternalServerError
4645
case TokenError:
47-
err.Code = http.StatusForbidden
46+
code = http.StatusForbidden
4847
case PermissionError:
49-
err.Code = http.StatusForbidden
48+
code = http.StatusForbidden
5049
case UserError:
51-
err.Code = http.StatusForbidden
50+
code = http.StatusForbidden
5251
case TwoFAError:
53-
err.Code = http.StatusForbidden
52+
code = http.StatusForbidden
5453
case OrderError:
55-
err.Code = http.StatusBadRequest
54+
code = http.StatusBadRequest
5655
case InputError:
57-
err.Code = http.StatusBadRequest
56+
code = http.StatusBadRequest
5857
case DataError:
59-
err.Code = http.StatusGatewayTimeout
58+
code = http.StatusGatewayTimeout
6059
case NetworkError:
61-
err.Code = http.StatusServiceUnavailable
60+
code = http.StatusServiceUnavailable
6261
default:
63-
err.Code = http.StatusInternalServerError
64-
err.ErrorType = GeneralError
62+
code = http.StatusInternalServerError
63+
etype = GeneralError
6564
}
6665

67-
return err
66+
return newError(etype, message, code, data)
67+
}
68+
69+
func newError(etype, message string, code int, data interface{}) Error {
70+
return Error{
71+
Message: message,
72+
ErrorType: etype,
73+
Data: data,
74+
Code: code,
75+
}
6876
}
6977

7078
// GetErrorName returns an error name given an HTTP code.

http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func readEnvelope(resp HTTPResponse, obj interface{}) error {
162162
return NewError(DataError, "Error parsing response.", nil)
163163
}
164164

165-
return NewError(e.ErrorType, e.Message, e.Data)
165+
return newError(e.ErrorType, e.Message, resp.Response.StatusCode, e.Data)
166166
}
167167

168168
// We now unmarshal the body.

0 commit comments

Comments
 (0)