Beispiel #1
0
        public async Task <TResponse> HandleResponseAsync <TResponse>(Task <TResponse> responseTask)
        {
            try
            {
                return(await responseTask);
            }
            catch (RpcException e) when(e.Status.StatusCode == StatusCode.Cancelled)
            {
                throw (e.Status.DebugException as OperationCanceledException) ?? new OperationCanceledException(e.Message);
            }
            catch (RpcException e) when((e.Status.StatusCode == StatusCode.Internal) && (e.Status.DebugException is HttpRequestException hre) && hre.Message.StartsWith("AbortError"))
            {
                throw new OperationCanceledException(hre.Message);
            }
            catch (RpcException e) when(e.Status.StatusCode == StatusCode.FailedPrecondition)
            {
                string errorMessage = e.Status.Detail;

                logger.LogWarning($"{nameof(OperationFailedException)}: {errorMessage}");

                messenger.AddError(localizer["OperationFailedExceptionMessengerTitle"], errorMessage);

                throw new OperationFailedException(errorMessage);
            }
        }