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

io.stargate.grpc.service.SingleExceptionHandler Maven / Gradle / Ivy

There is a newer version: 2.1.0-BETA-19
Show newest version
package io.stargate.grpc.service;

import io.grpc.Metadata;
import io.grpc.Status;
import io.grpc.stub.StreamObserver;
import io.stargate.proto.QueryOuterClass;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class SingleExceptionHandler extends ExceptionHandler {

  private final StreamObserver responseObserver;

  public SingleExceptionHandler(StreamObserver responseObserver) {
    this.responseObserver = responseObserver;
  }

  @Override
  protected void onError(
      @Nullable Status status, @Nonnull Throwable throwable, @Nullable Metadata trailer) {
    if (status == null) {
      responseObserver.onError(throwable);
      return;
    }
    status = status.withDescription(throwable.getMessage()).withCause(throwable);
    responseObserver.onError(
        trailer != null ? status.asRuntimeException(trailer) : status.asRuntimeException());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy