in plugin-tester-scala/src/main/scala/example/myapp/helloworld/LoggingErrorHandlingGreeterServer.scala [59:82]
private def loggingErrorHandlingGrpcRoute[ServiceImpl](
buildImpl: RequestContext => ServiceImpl,
errorHandler: ErrorHandler,
buildHandler: (ServiceImpl, ErrorHandler) => HttpRequest => Future[HttpResponse]): Route =
DebuggingDirectives.logRequestResult(("loggingErrorHandlingGrpcRoute", Logging.InfoLevel)) {
extractRequestContext { ctx =>
val loggingErrorHandler: ErrorHandler = (sys: ActorSystem) => {
case NonFatal(t) =>
val pf = errorHandler(sys)
if (pf.isDefinedAt(t)) {
val trailers: Trailers = pf(t)
ctx.log.error(t, s"Grpc failure handled and mapped to $trailers")
trailers
} else {
val trailers = Trailers(Status.INTERNAL)
ctx.log.error(t, s"Grpc failure UNHANDLED and mapped to $trailers")
trailers
}
}
val impl = buildImpl(ctx)
val handler = buildHandler(impl, loggingErrorHandler)
handle(handler)
}
}