Skip to content

Commit

Permalink
Log any errors that were not handled by grpc handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignas committed Aug 15, 2024
1 parent 36af9d9 commit 3a67131
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/lt/pow/nukagit/grpc/GrpcHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.stub.StreamObserver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.Function;

public class GrpcHelpers {
private static final Logger LOGGER = LoggerFactory.getLogger(GrpcHelpers.class);

public static <RQ, RS> void unaryCall(RQ request, StreamObserver<RS> responseObserver, Function<RQ, RS> method) {
RS response;
try {
Expand All @@ -15,6 +19,7 @@ public static <RQ, RS> void unaryCall(RQ request, StreamObserver<RS> responseObs
responseObserver.onError(e);
return;
} catch (Exception e) {
LOGGER.error("Error processing request", e);
responseObserver.onError(Status.INTERNAL.withDescription(e.getMessage()).asRuntimeException());
return;
}
Expand Down

0 comments on commit 3a67131

Please sign in to comment.