Allow StatusException to set its own headers

This commit is contained in:
Dave Syer
2025-01-13 10:35:28 +00:00
parent 87e26c378e
commit 71355e6ff6

View File

@@ -85,7 +85,7 @@ public class GrpcExceptionHandlerInterceptor implements ServerInterceptor {
super.onReady();
}
catch (Throwable t) {
this.call.close(this.exceptionHandler.handleException(t), new Metadata());
this.call.close(this.exceptionHandler.handleException(t), headers(t));
}
}
@@ -95,7 +95,7 @@ public class GrpcExceptionHandlerInterceptor implements ServerInterceptor {
super.onMessage(message);
}
catch (Throwable t) {
this.call.close(this.exceptionHandler.handleException(t), new Metadata());
this.call.close(this.exceptionHandler.handleException(t), headers(t));
}
}
@@ -105,10 +105,15 @@ public class GrpcExceptionHandlerInterceptor implements ServerInterceptor {
super.onHalfClose();
}
catch (Throwable t) {
this.call.close(this.exceptionHandler.handleException(t), new Metadata());
this.call.close(this.exceptionHandler.handleException(t), headers(t));
}
}
private Metadata headers(Throwable t) {
Metadata result = Status.trailersFromThrowable(t);
return result != null ? result : new Metadata();
}
}
static class FallbackHandler implements GrpcExceptionHandler {