/// <summary> /// Translates the GRPC exception into a Vector exception /// </summary> /// <param name="grpcException">The GRPC exception.</param> /// <returns>Translated exception</returns> private static Exception TranslateGrpcException(Grpc.Core.RpcException grpcException) { switch (grpcException.StatusCode) { case Grpc.Core.StatusCode.Cancelled: if (grpcException.Status.Detail == "Received http2 header with status: 401") { return(new VectorUnauthenticatedException("Authentication Failed. Please check your connection configuration.", grpcException)); } return(new TaskCanceledException("Operation was cancelled", grpcException)); case Grpc.Core.StatusCode.DeadlineExceeded: return(new VectorTimeoutException("Communication with Vector timed out", grpcException)); case Grpc.Core.StatusCode.Unauthenticated: return(new VectorUnauthenticatedException("Authentication Failed. Please check your connection configuration.", grpcException)); case Grpc.Core.StatusCode.Unavailable: return(new VectorUnavailableException("Unable to reach Vector.", grpcException)); case Grpc.Core.StatusCode.Unimplemented: return(new VectorUnimplementedException("Vector does not handle this message.", grpcException)); default: return(new VectorConnectionException("Connection to Vector failed.", grpcException)); } }
private void HandleErrorException(GrpcProxyMethod method, Exception e, GrpcCore.RpcException rpcException) { string?errorType = null; string?message = null; string?faultCode = null;; byte[]? faultDetails = null; byte[]? serializedErrorInfo = null; foreach (var entry in rpcException.Trailers) { switch (entry.Key) { case WellKnownHeaderKeys.ErrorType: errorType = entry.Value; break; case WellKnownHeaderKeys.ErrorMessage: message = entry.Value; break; case WellKnownHeaderKeys.ErrorCode: faultCode = entry.Value; break; case WellKnownHeaderKeys.ErrorDetails: faultDetails = entry.ValueBytes; break; case WellKnownHeaderKeys.ErrorInfo: serializedErrorInfo = entry.ValueBytes; break; } if (serializedErrorInfo != null) { // Serialized error info takes precedence, so no need to look for other error keys. break; } } RpcError?rpcError = null; if (serializedErrorInfo != null) { var actualSerializer = method.SerializerOverride ?? this.serializer; rpcError = actualSerializer.Deserialize <RpcError>(serializedErrorInfo); } else if (!string.IsNullOrEmpty(errorType)) { rpcError = new RpcError { ErrorType = errorType, ErrorCode = faultCode, Message = message, ErrorDetails = faultDetails }; } if (rpcError != null) { this.HandleRpcError(method, rpcError); } throw new RpcFailureException(RpcFailure.Unknown, e.Message, e); }