Skip to content

Commit 0a9d5ca

Browse files
committed
Skip JSON parsing for non-JSON error responses
Check Content-Type header before unmarshaling errors to avoid unnecessary JSON parsing overhead for plain text responses. Signed-off-by: Jan Rodák <[email protected]>
1 parent f29cdc7 commit 0a9d5ca

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/bindings/errors.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ func (h *APIResponse) ProcessWithError(unmarshalInto interface{}, unmarshalError
4747
if h.IsConflictError() {
4848
return handleError(data, unmarshalErrorInto)
4949
}
50-
51-
// TODO should we add a debug here with the response code?
52-
return handleError(data, &errorhandling.ErrorModel{})
50+
if h.Response.Header.Get("Content-Type") == "application/json" {
51+
return handleError(data, &errorhandling.ErrorModel{})
52+
}
53+
return &errorhandling.ErrorModel{
54+
Message: string(data),
55+
ResponseCode: h.Response.StatusCode,
56+
}
5357
}
5458

5559
func CheckResponseCode(inError error) (int, error) {

0 commit comments

Comments
 (0)