Browse Source

Resolved #4590: DynamicHttpProxyInterceptor mask real StatusCode.

pull/6043/head
Halil İbrahim Kalkan 6 years ago
parent
commit
66cadb34cc
  1. 1
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/UserExceptionInformer.cs
  2. 14
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultHttpExceptionStatusCodeFinder.cs
  3. 7
      framework/src/Volo.Abp.Core/Volo/Abp/ExceptionHandling/IHasHttpStatusCode.cs
  4. 4
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpRemoteCallException.cs
  5. 16
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs

1
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/UserExceptionInformer.cs

@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.AspNetCore.ExceptionHandling;

14
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultHttpExceptionStatusCodeFinder.cs

@ -22,7 +22,13 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
public virtual HttpStatusCode GetStatusCode(HttpContext httpContext, Exception exception)
{
if (exception is IHasErrorCode exceptionWithErrorCode &&
if (exception is IHasHttpStatusCode exceptionWithHttpStatusCode &&
exceptionWithHttpStatusCode.HttpStatusCode > 0)
{
return (HttpStatusCode) exceptionWithHttpStatusCode.HttpStatusCode;
}
if (exception is IHasErrorCode exceptionWithErrorCode &&
!exceptionWithErrorCode.Code.IsNullOrWhiteSpace())
{
if (Options.ErrorCodeToHttpStatusCodeMappings.TryGetValue(exceptionWithErrorCode.Code, out var status))
@ -39,7 +45,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
}
//TODO: Handle SecurityException..?
if (exception is AbpValidationException)
{
return HttpStatusCode.BadRequest;
@ -59,8 +65,8 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
{
return HttpStatusCode.Forbidden;
}
return HttpStatusCode.InternalServerError;
}
}
}
}

7
framework/src/Volo.Abp.Core/Volo/Abp/ExceptionHandling/IHasHttpStatusCode.cs

@ -0,0 +1,7 @@
namespace Volo.Abp.ExceptionHandling
{
public interface IHasHttpStatusCode
{
int HttpStatusCode { get; }
}
}

4
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpRemoteCallException.cs

@ -5,8 +5,10 @@ using Volo.Abp.ExceptionHandling;
namespace Volo.Abp.Http.Client
{
[Serializable]
public class AbpRemoteCallException : AbpException, IHasErrorCode, IHasErrorDetails
public class AbpRemoteCallException : AbpException, IHasErrorCode, IHasErrorDetails, IHasHttpStatusCode
{
public int HttpStatusCode { get; set; }
public string Code => Error?.Code;
public string Details => Error?.Details;

16
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs

@ -252,10 +252,22 @@ namespace Volo.Abp.Http.Client.DynamicProxying
await response.Content.ReadAsStringAsync()
);
throw new AbpRemoteCallException(errorResponse.Error);
throw new AbpRemoteCallException(errorResponse.Error)
{
HttpStatusCode = (int) response.StatusCode
};
}
throw new AbpException($"Remote service returns error! HttpStatusCode: {response.StatusCode}, ReasonPhrase: {response.ReasonPhrase}");
throw new AbpRemoteCallException(
new RemoteServiceErrorInfo
{
Message = response.ReasonPhrase,
Code = response.StatusCode.ToString()
}
)
{
HttpStatusCode = (int) response.StatusCode
};
}
protected virtual CancellationToken GetCancellationToken()

Loading…
Cancel
Save