org.lognet.springboot.grpc.recovery.ErrorHandlerAdapter Maven / Gradle / Ivy
The newest version!
// Generated by delombok at Wed Sep 27 05:27:18 UTC 2023
package org.lognet.springboot.grpc.recovery;
import io.grpc.Status;
import java.util.Optional;
import org.lognet.springboot.grpc.GRpcErrorHandler;
public class ErrorHandlerAdapter {
@java.lang.SuppressWarnings("all")
private static final org.slf4j.Logger log =
org.slf4j.LoggerFactory.getLogger(ErrorHandlerAdapter.class);
private final Optional errorHandler;
public ErrorHandlerAdapter(Optional errorHandler) {
this.errorHandler = errorHandler;
}
protected Status handle(Exception e, Status status, GRpcExceptionScope scope) {
if (errorHandler.isPresent()) {
return errorHandler
.get()
.handle(
scope.getRequestOrResponse(),
status,
e,
scope.getCallHeaders(),
scope.getResponseHeaders());
} else {
log.error("Got error with status {} ", status.getCode().name(), e);
return status.withDescription(e.getMessage());
}
}
}