All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.grpc.runtime.supports.exc.DefaultExceptionHandlerProvider Maven / Gradle / Ivy

There is a newer version: 3.15.1
Show newest version
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);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy