Client can handle on HTTP error different common error formats
Closed this issue · 0 comments
krnkl commented
Client can be more aware of a common error format in the response body.
I.e. in the code below we expect only error with specific format:
if response.StatusCode != http.StatusOK {
problem := problemJSON{}
err := json.NewDecoder(response.Body).Decode(&problem)
if err != nil {
return errors.Wrap(err, "unable to decode response body")
}
return errors.Errorf("%s: %s", msg, problem.Detail)
}
where problem looks like:
{
"title": "InternalServerError",
"detail": "Something bad happend",
"status": 500,
"type:": "https://httpstatuses.com/500"
}
However, Nakadi returns different type of error when request is not authorised, which is:
{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}
Thus, this error is swallowed and only status code is returned which cannot sometimes properly identify the cause.