Search in sources :

Example 1 with PluginException

use of com.hotels.styx.api.plugins.spi.PluginException in project styx by ExpediaGroup.

the class HttpErrorStatusMetricsTest method pluginExceptionsAreNotRecordedAsStyxUnexpectedErrors.

@Test
public void pluginExceptionsAreNotRecordedAsStyxUnexpectedErrors() {
    errorListener.proxyErrorOccurred(INTERNAL_SERVER_ERROR, new PluginException("bad"));
    assertThat(count(ERROR), is(0));
}
Also used : PluginException(com.hotels.styx.api.plugins.spi.PluginException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with PluginException

use of com.hotels.styx.api.plugins.spi.PluginException in project styx by ExpediaGroup.

the class HttpPipelineHandler method exceptionToResponse.

private LiveHttpResponse exceptionToResponse(Throwable cause, LiveHttpRequest request, CharSequence originsHeaderName) {
    HttpResponseStatus status = status(cause instanceof PluginException ? cause.getCause() : cause);
    String message = status.code() >= 500 ? "Site temporarily unavailable." : status.description();
    LiveHttpResponse.Transformer builder = responseEnhancer.enhance(response(status).body(new ByteStream(Flux.just(new Buffer(message, UTF_8)))).build().newBuilder(), request).header(CONTENT_LENGTH, message.getBytes(UTF_8).length).header(CONNECTION, "close");
    if (originsHeaderName != null && originFromException(cause) != null) {
        return builder.header(originsHeaderName, originFromException(cause)).build();
    } else {
        return builder.build();
    }
}
Also used : Buffer(com.hotels.styx.api.Buffer) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) PluginException(com.hotels.styx.api.plugins.spi.PluginException) ByteStream(com.hotels.styx.api.ByteStream) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse)

Aggregations

PluginException (com.hotels.styx.api.plugins.spi.PluginException)2 Buffer (com.hotels.styx.api.Buffer)1 ByteStream (com.hotels.styx.api.ByteStream)1 HttpResponseStatus (com.hotels.styx.api.HttpResponseStatus)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1