pmorie / osb-broker-lib

A go library for developing an Open Service Broker
Apache License 2.0
28 stars 23 forks source link

Wrong status codes being returned for many error conditions #54

Closed sgran closed 4 years ago

sgran commented 4 years ago

Hi,

The OpenServiceBroker API Specification for responses to provision requests (here) allows my code to return 400 for several error conditions. I've done my best to follow the specification, and a typical response might be:

    if !found {
        return brokerapi.NewFailureResponseBuilder(
            errors.New("NoService"), http.StatusBadRequest, "Service not found",
        ).WithErrorKey("NoService").Build()
    }

I am using the OSB Checker to check my application, and I saw that none of the error codes I was returning were being respected. Then I found:


    response, err := s.Broker.Provision(request, c)
    if err != nil {
        s.writeError(w, err, http.StatusInternalServerError)
        return
    }

So, my careful use of FailureResponse structs is being swallowed by the API conversion to error, and a 500 is being returned whenever I return a non-nil error.

I can see that the best way to change this is to modify the method prototypes to return a FailureResponse, but this represents quite a breaking API change, so I wanted to raise it as an issue and discuss options before branching and so on.

Thanks for your work!

sgran commented 4 years ago

I'm sorry, I've finally found the way to return the right error conditions with the client library. I'll close.