io.quarkus.grpc.runtime.supports.exc.DefaultExceptionHandlerProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-grpc Show documentation
Show all versions of quarkus-grpc Show documentation
Serve and consume gRPC services
package io.quarkus.grpc.runtime.supports.exc;
import jakarta.enterprise.context.ApplicationScoped;
import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.StatusException;
import io.quarkus.arc.DefaultBean;
import io.quarkus.grpc.ExceptionHandler;
import io.quarkus.grpc.ExceptionHandlerProvider;
@ApplicationScoped
@DefaultBean
public class DefaultExceptionHandlerProvider implements ExceptionHandlerProvider {
@Override
public ExceptionHandler createHandler(ServerCall.Listener listener,
ServerCall call, Metadata metadata) {
return new DefaultExceptionHandler<>(listener, call, metadata);
}
private static class DefaultExceptionHandler extends ExceptionHandler {
public DefaultExceptionHandler(ServerCall.Listener listener, ServerCall call,
Metadata metadata) {
super(listener, call, metadata);
}
@Override
protected void handleException(Throwable exception, ServerCall call, Metadata metadata) {
StatusException se = (StatusException) ExceptionHandlerProvider.toStatusException(exception, false);
Metadata trailers = se.getTrailers() != null ? se.getTrailers() : metadata;
call.close(se.getStatus(), trailers);
}
}
}