bastion-dev / Bastion

Java test library for HTTP APIs
http://bastion.rocks
GNU General Public License v3.0
13 stars 8 forks source link

HTTP response details are not printed if .bind() fails. #73

Closed FrelliBB closed 7 years ago

FrelliBB commented 7 years ago

Given that I have a server which only accepts application/x-www-form-urlencoded (and will return an exception message in the response body if the content-type header is anything different) and I make the following request:

        Bastion.request(JsonRequest.postFromString(wizardsEndpoint, "{\"name\":\"Harry Potter\"}"))
                .bind(Wizard.class)
                .withAssertions((statusCode, response, model) -> {
                    assertThat(statusCode).isEqualTo(200);
                })
                .call();

then the following exception is thrown:

java.lang.AssertionError: Could not parse response into model object of type com.hogwarts.exceptions.UnsupportedMediaTypeExceptionResponse

    at rocks.bastion.core.BastionBuilderImpl.decodeModel(BastionBuilderImpl.java:188)
    at rocks.bastion.core.BastionBuilderImpl.call(BastionBuilderImpl.java:101)

Decoding of the exception into a Wizard failed and the actual response from the server was not logged at any point. It is not clear whether the server sent back an exception message or if Bastion was not able to decode the response.

KPull commented 7 years ago

Good point. We should fix this.

So the problem here is that in BastionBuilderImpl.call(), if decodeModel() does not return, then the modelResponse variable is not set which is subsequently not sent to the listeners in the catch clause. We should keep the response we get from the RequestExecutor as a field and pass that instead to the listeners in the catch clauses.

KPull commented 7 years ago

Fixed in #74.