in plugin-tester-java/src/main/java/example/myapp/helloworld/LoggingErrorHandlingGreeterServer.java [79:123]
private static <ServiceImpl> Route loggingErrorHandlingGrpcRoute(
Function<RequestContext, ServiceImpl> buildImpl,
Function<ActorSystem, Function<Throwable, Trailers>> errorHandler,
BiFunction<
ServiceImpl,
Function<ActorSystem, Function<Throwable, Trailers>>,
org.apache.pekko.japi.function.Function<HttpRequest, CompletionStage<HttpResponse>>>
buildHandler) {
return logRequest(
"loggingErrorHandlingGrpcRoute",
Logging.InfoLevel(),
() ->
extractRequestContext(
ctx -> {
Function<ActorSystem, Function<Throwable, Trailers>> loggingErrorHandler =
(actorSystem) ->
(throwable) -> {
Function<Throwable, Trailers> function =
errorHandler.apply(actorSystem);
Trailers trailers = function.apply(throwable);
if (trailers != null) {
ctx.getLog()
.error(
throwable, "Grpc failure handled and mapped to " + trailers);
return trailers;
} else {
Trailers internal = new Trailers(Status.INTERNAL);
ctx.getLog()
.error(
throwable,
"Grpc failure UNHANDLED and mapped to " + internal);
return internal;
}
};
try {
ServiceImpl impl = buildImpl.apply(ctx);
org.apache.pekko.japi.function.Function<
HttpRequest, CompletionStage<HttpResponse>>
handler = buildHandler.apply(impl, loggingErrorHandler);
return handle(handler);
} catch (Exception e) {
return failWith(e);
}
}));
}