@Override public void onError(Throwable ex) { logger.warn("Received error from server: {}", ex.getMessage()); subscriberStreamObserver = null; if (ex instanceof StatusRuntimeException && ((StatusRuntimeException) ex).getStatus().getCode().equals( Status.UNAVAILABLE.getCode())) { return; } resubscribe(); }
@Override public void onError(Throwable ex) { logger.warn("Received error from server: {}", ex.getMessage()); outboundStreamObserver = null; if (ex instanceof StatusRuntimeException && ((StatusRuntimeException) ex).getStatus().getCode().equals(Status.UNAVAILABLE.getCode())) { return; } resubscribe(); }
/** * Override to change what data from the status or trailers are parsed into the span modeling it. * By default, this tags "grpc.status_code" and "error" when it is not OK. */ protected void onClose(Status status, Metadata trailers, SpanCustomizer span) { if (status != null && status.getCode() != Status.Code.OK) { String code = String.valueOf(status.getCode()); span.tag("grpc.status_code", code); span.tag("error", code); } } }
/** * Returns the error code corresponding to a gRPC status, or {@code UNKNOWN} if not recognized. */ static ErrorCode fromGrpcStatus(Status status) { ErrorCode code = errorByRpcCode.get(status.getCode().value()); return code == null ? UNKNOWN : code; }
@Override public void onError(Throwable throwable) { logger.debug("Lost instruction stream from {} - {}", name, throwable.getMessage()); disconnectListeners.forEach(Runnable::run); if( throwable instanceof StatusRuntimeException) { StatusRuntimeException sre = (StatusRuntimeException)throwable; if( sre.getStatus().getCode().equals(Status.Code.PERMISSION_DENIED)) return; } scheduleReconnect(true); }
/** Determines whether we need to initiate a longer backoff due to system overload. */ private static boolean isResourceExhaustedError(Throwable throwable) { return getStatus(throwable).getCode().equals(Code.RESOURCE_EXHAUSTED); }; }
private boolean isDeadlineExceeded(Throwable throwable) { return throwable instanceof StatusRuntimeException && ((StatusRuntimeException) throwable).getStatus().getCode().equals(Status.Code.DEADLINE_EXCEEDED); }
@Override public void run() { listener.onEvent( null, throwable instanceof FirestoreException ? (FirestoreException) throwable : FirestoreException.apiException( new ApiException( throwable, GrpcStatusCode.of(getStatus(throwable).getCode()), false))); } });
private static void assertResponseTimeoutExceptionOrDeadlineExceeded(@Nullable Throwable cause) { assertThat(cause).isNotNull(); // Both exceptions can be raised when a timeout occurs due to timing issues, // and the first triggered one wins. if (cause instanceof ResponseTimeoutException) { return; } if (cause instanceof StatusException) { assertThat(((StatusException) cause).getStatus().getCode()).isEqualTo(Code.DEADLINE_EXCEEDED); return; } fail("cause must be a ResponseTimeoutException or a StatusException: ", cause); }
private void awaitException(Code expectedCode) throws InterruptedException { FirestoreException exception = exceptions.take(); if (expectedCode != null) { assertEquals(expectedCode, exception.getStatus().getCode()); } }
@Test public void httpNotOk() { reader.onSubscribe(subscription); verifyZeroInteractions(subscription); reader.onNext(HttpHeaders.of(HttpStatus.UNAUTHORIZED)); verifyZeroInteractions(subscription); verifyZeroInteractions(deframer); verify(transportStatusListener).transportReportStatus( argThat(s -> s.getCode() == Status.UNAUTHENTICATED.getCode())); } }
@Test public void tooLargeRequest_uncompressed() throws Exception { final SimpleRequest request = newLargeRequest(); final StatusRuntimeException t = (StatusRuntimeException) catchThrowable( () -> blockingClient.staticUnaryCall(request)); assertThat(t.getStatus().getCode()).isEqualTo(Code.CANCELLED); checkRequestLogStatus(grpcStatus -> { assertThat(grpcStatus.getCode()).isEqualTo(Code.RESOURCE_EXHAUSTED); }); }
/** Sends an rpc to an unimplemented method within TestService. */ @Test public void unimplementedMethod() throws Exception { final Throwable t = catchThrowable(() -> blockingStub.unimplementedCall(Empty.getDefaultInstance())); assertThat(t).isInstanceOf(StatusRuntimeException.class); assertThat(((StatusRuntimeException) t).getStatus().getCode()) .isEqualTo(Status.UNIMPLEMENTED.getCode()); checkRequestLogError((headers, rpcReq, cause) -> { assertThat(rpcReq).isNotNull(); assertThat(rpcReq.params()).containsExactly(Empty.getDefaultInstance()); assertThat(headers.get(GrpcHeaderNames.GRPC_STATUS)).isEqualTo( String.valueOf(Status.UNIMPLEMENTED.getCode().value())); }); }
@Test public void error_withMessage() throws Exception { final StatusRuntimeException t = (StatusRuntimeException) catchThrowable( () -> blockingClient.errorWithMessage(REQUEST_MESSAGE)); assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED); assertThat(t.getStatus().getDescription()).isEqualTo("aborted call"); checkRequestLog((rpcReq, rpcRes, grpcStatus) -> { assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/ErrorWithMessage"); assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE); assertThat(grpcStatus).isNotNull(); assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED); assertThat(grpcStatus.getDescription()).isEqualTo("aborted call"); }); }
@Test public void error_thrown_unary() throws Exception { final StatusRuntimeException t = (StatusRuntimeException) catchThrowable( () -> blockingClient.unaryThrowsError(REQUEST_MESSAGE)); assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED); assertThat(t.getStatus().getDescription()).isEqualTo("call aborted"); checkRequestLog((rpcReq, rpcRes, grpcStatus) -> { assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/UnaryThrowsError"); assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE); assertThat(grpcStatus).isNotNull(); assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED); assertThat(grpcStatus.getDescription()).isEqualTo("call aborted"); }); }
@Test public void tooLargeRequest_compressed() throws Exception { final SimpleRequest request = newLargeRequest(); final StatusRuntimeException t = (StatusRuntimeException) catchThrowable( () -> blockingClient.withCompression("gzip").staticUnaryCall(request)); assertThat(t.getStatus().getCode()).isEqualTo(Code.CANCELLED); checkRequestLogStatus(grpcStatus -> { assertThat(grpcStatus.getCode()).isEqualTo(Code.RESOURCE_EXHAUSTED); }); }
@Test public void error_thrown_streamStub() throws Exception { final StreamRecorder<SimpleResponse> response = StreamRecorder.create(); streamingClient.streamThrowsErrorInStub(response); response.awaitCompletion(); final StatusRuntimeException t = (StatusRuntimeException) response.getError(); assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED); assertThat(t.getStatus().getDescription()).isEqualTo("bad streaming stub"); checkRequestLogStatus(grpcStatus -> { assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED); assertThat(grpcStatus.getDescription()).isEqualTo("bad streaming stub"); }); }
@Test public void error_noMessage() throws Exception { final StatusRuntimeException t = (StatusRuntimeException) catchThrowable( () -> blockingClient.errorNoMessage(REQUEST_MESSAGE)); assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED); assertThat(t.getStatus().getDescription()).isNull(); checkRequestLog((rpcReq, rpcRes, grpcStatus) -> { assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/ErrorNoMessage"); assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE); assertThat(grpcStatus).isNotNull(); assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED); assertThat(grpcStatus.getDescription()).isNull(); }); }
/** Convert an entry's status from a protobuf to an {@link ApiException}. */ private ApiException createEntryError(com.google.rpc.Status protoStatus) { io.grpc.Status grpcStatus = io.grpc.Status.fromCodeValue(protoStatus.getCode()) .withDescription(protoStatus.getMessage()); StatusCode gaxStatusCode = GrpcStatusCode.of(grpcStatus.getCode()); return ApiExceptionFactory.createException( grpcStatus.asRuntimeException(), gaxStatusCode, retryableCodes.contains(gaxStatusCode.getCode())); }