Browse Source

Enhance the error that occurs during the http request.

pull/10387/head
maliming 5 years ago
parent
commit
0bc8a4a261
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 6
      framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs
  2. 9
      framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/Http/Client/AbpRemoteCallException.cs
  3. 19
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs

6
framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs

@ -42,7 +42,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
{
var errorInfo = CreateErrorInfoWithoutCode(exception, includeSensitiveDetails);
if (exception is IHasErrorCode hasErrorCodeException)
if (exception is IHasErrorCode hasErrorCodeException && hasErrorCodeException.Code.IsNullOrWhiteSpace())
{
errorInfo.Code = hasErrorCodeException.Code;
}
@ -61,7 +61,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
if (exception is AbpRemoteCallException remoteCallException)
{
return remoteCallException.Error;
return remoteCallException.Error ?? new RemoteServiceErrorInfo(remoteCallException.Message);
}
if (exception is AbpDbConcurrencyException)
@ -175,7 +175,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
return new RemoteServiceErrorInfo(exception.Message);
}
protected virtual Exception TryToGetActualException(Exception exception)
{
if (exception is AggregateException && exception.InnerException != null)

9
framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/Http/Client/AbpRemoteCallException.cs

@ -15,7 +15,14 @@ namespace Volo.Abp.Http.Client
public RemoteServiceErrorInfo Error { get; set; }
public AbpRemoteCallException()
public AbpRemoteCallException(string message)
: base(message)
{
}
public AbpRemoteCallException(string message, Exception innerException)
: base(message, innerException)
{
}

19
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/ClientProxying/ClientProxyBase.cs

@ -132,11 +132,20 @@ namespace Volo.Abp.Http.Client.ClientProxying
);
}
var response = await client.SendAsync(
requestMessage,
HttpCompletionOption.ResponseHeadersRead /*this will buffer only the headers, the content will be used as a stream*/,
GetCancellationToken(requestContext.Arguments)
);
HttpResponseMessage response;
try
{
response = await client.SendAsync(
requestMessage,
HttpCompletionOption
.ResponseHeadersRead /*this will buffer only the headers, the content will be used as a stream*/,
GetCancellationToken(requestContext.Arguments)
);
}
catch (Exception ex)
{
throw new AbpRemoteCallException($"An error occurred during the ABP remote HTTP request. ({ex.Message}) See the inner exception for details.", ex);
}
if (!response.IsSuccessStatusCode)
{

Loading…
Cancel
Save