feat(client): add option to keep the request URL on 404 errors
What does this MR do?
For a 404, CheckResponse returned the shared ErrNotFound value. That
value has no Response, so the error printed only 404 Not Found. Every
other status prints the method and URL. A 404 is often caused by a wrong
host or path, so this was the error where the URL mattered most.
This MR adds a WithDetailedNotFoundErrors() client option. With it, a 404
builds a per-request *ErrorResponse with Response, Body and Message
filled in, like every other status:
Before: 404 Not Found
After: GET https://gitlab.com/api/v4/projects/mygroup%2Fmyproject: 404 {message: 404 Project Not Found}GraphQL errors now expose their status code
GraphQLResponseError now has an Unwrap method, so errors.Is,
errors.As, HasStatusCode and StatusCode reach the underlying
*ErrorResponse. This applies to every GraphQL HTTP failure with a JSON body
(400, 429, 500, ...), not only 404s
Upgrade notes
To get the detailed 404 errors, switch any err == gitlab.ErrNotFound
comparisons to errors.Is(err, gitlab.ErrNotFound), then enable the option:
client, err := gitlab.NewClient(token, gitlab.WithDetailedNotFoundErrors())Closes #2334 (closed)