use of ratpack.error.ServerErrorHandler in project ratpack by ratpack.
the class DefaultContext method error.
public void error(Throwable throwable) {
ServerErrorHandler serverErrorHandler = get(ServerErrorHandler.TYPE);
throwable = unpackThrowable(throwable);
ThrowableHolder throwableHolder = getRequest().maybeGet(ThrowableHolder.TYPE).orElse(null);
if (throwableHolder == null) {
getRequest().add(ThrowableHolder.TYPE, new ThrowableHolder(throwable));
try {
if (throwable instanceof InvalidPathEncodingException) {
serverErrorHandler.error(this, (InvalidPathEncodingException) throwable);
} else {
serverErrorHandler.error(this, throwable);
}
} catch (Throwable errorHandlerThrowable) {
onErrorHandlerError(serverErrorHandler, throwable, errorHandlerThrowable);
}
} else {
onErrorHandlerError(serverErrorHandler, throwableHolder.getThrowable(), throwable);
}
}
use of ratpack.error.ServerErrorHandler in project ratpack by ratpack.
the class DefaultRequestFixture method getEffectiveRegistry.
private Registry getEffectiveRegistry(final DefaultHandlingResult.ResultsHolder results) {
ClientErrorHandler clientErrorHandler = (context, statusCode) -> {
results.setClientError(statusCode);
context.getResponse().status(statusCode);
results.getLatch().countDown();
};
ServerErrorHandler serverErrorHandler = (context, throwable1) -> {
results.setThrowable(throwable1);
results.getLatch().countDown();
};
final Registry userRegistry = Registry.builder().add(ClientErrorHandler.class, clientErrorHandler).add(ServerErrorHandler.class, serverErrorHandler).build();
return Exceptions.uncheck(() -> {
ServerConfig serverConfig = serverConfigBuilder.build();
DefaultExecController execController = new DefaultExecController(serverConfig.getThreads());
return ServerRegistry.serverRegistry(new TestServer(), Impositions.none(), execController, serverConfig, r -> userRegistry.join(registryBuilder.build()));
});
}
Aggregations