Skip to content

Commit

Permalink
Merge pull request #55704 from soltysh/return_real_error
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Return original error instead of negotiation one

**What this PR does / why we need it**:
When the requested type (eg. `text/html`) is not available and we're trying to hit an endpoint to which a user is for unauthorized we'll get 406, instead of 403. The reason for that is that, even if error happens we're trying to match the serializer, which fails and results in swallowing error, instead of returning raw json, for example. 

This fix returns raw json for such situations.

**Release note**:
```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue committed Nov 28, 2017
2 parents 710a124 + 7c83e73 commit 85f0a1a
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func SerializeObject(mediaType string, encoder runtime.Encoder, w http.ResponseW
func WriteObjectNegotiated(ctx request.Context, s runtime.NegotiatedSerializer, gv schema.GroupVersion, w http.ResponseWriter, req *http.Request, statusCode int, object runtime.Object) {
serializer, err := negotiation.NegotiateOutputSerializer(req, s)
if err != nil {
// if original statusCode was not successful we need to return the original error
// we cannot hide it behind negotiation problems
if statusCode < http.StatusOK || statusCode >= http.StatusBadRequest {
WriteRawJSON(int(statusCode), object, w)
return
}
status := ErrorToAPIStatus(err)
WriteRawJSON(int(status.Code), status, w)
return
Expand Down

0 comments on commit 85f0a1a

Please sign in to comment.