Browse Source

Resolved #9328: Return a better exception message and HTTP status code for optimistic concurrency exceptions

Now, it returns 409 with more meaningful message.
pull/9350/head
Halil İbrahim Kalkan 5 years ago
parent
commit
12677fb230
  1. 6
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultHttpExceptionStatusCodeFinder.cs
  2. 16
      framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/AspNetCore/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs
  3. 1
      framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/ExceptionHandling/Localization/en.json
  4. 1
      framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/ExceptionHandling/Localization/tr.json

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

@ -3,6 +3,7 @@ using System.Net;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.Authorization; using Volo.Abp.Authorization;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.ExceptionHandling; using Volo.Abp.ExceptionHandling;
@ -55,6 +56,11 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
{ {
return HttpStatusCode.NotFound; return HttpStatusCode.NotFound;
} }
if (exception is AbpDbConcurrencyException)
{
return HttpStatusCode.Conflict;
}
if (exception is NotImplementedException) if (exception is NotImplementedException)
{ {

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

@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.Authorization; using Volo.Abp.Authorization;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.ExceptionHandling; using Volo.Abp.ExceptionHandling;
@ -58,14 +59,19 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
exception = TryToGetActualException(exception); exception = TryToGetActualException(exception);
if (exception is EntityNotFoundException) if (exception is AbpRemoteCallException remoteCallException)
{ {
return CreateEntityNotFoundError(exception as EntityNotFoundException); return remoteCallException.Error;
} }
if (exception is AbpRemoteCallException remoteCallException) if (exception is AbpDbConcurrencyException)
{ {
return remoteCallException.Error; return new RemoteServiceErrorInfo(L["AbpDbConcurrencyErrorMessage"]);
}
if (exception is EntityNotFoundException)
{
return CreateEntityNotFoundError(exception as EntityNotFoundException);
} }
var errorInfo = new RemoteServiceErrorInfo(); var errorInfo = new RemoteServiceErrorInfo();
@ -169,7 +175,7 @@ namespace Volo.Abp.AspNetCore.ExceptionHandling
return new RemoteServiceErrorInfo(exception.Message); return new RemoteServiceErrorInfo(exception.Message);
} }
protected virtual Exception TryToGetActualException(Exception exception) protected virtual Exception TryToGetActualException(Exception exception)
{ {
if (exception is AggregateException && exception.InnerException != null) if (exception is AggregateException && exception.InnerException != null)

1
framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/ExceptionHandling/Localization/en.json

@ -13,6 +13,7 @@
"DefaultErrorMessage404": "Resource not found!", "DefaultErrorMessage404": "Resource not found!",
"DefaultErrorMessage404Detail": "The resource requested could not found on the server!", "DefaultErrorMessage404Detail": "The resource requested could not found on the server!",
"EntityNotFoundErrorMessage": "There is no entity {0} with id = {1}!", "EntityNotFoundErrorMessage": "There is no entity {0} with id = {1}!",
"AbpDbConcurrencyErrorMessage": "The data you have submitted has already changed by another user/client. Please discard the changes you've done and try from the beginning.",
"Error": "Error", "Error": "Error",
"UnhandledException": "Unhandled exception!", "UnhandledException": "Unhandled exception!",
"401Message": "Unauthorized", "401Message": "Unauthorized",

1
framework/src/Volo.Abp.ExceptionHandling/Volo/Abp/ExceptionHandling/Localization/tr.json

@ -13,6 +13,7 @@
"DefaultErrorMessage404": "Kaynak bulunamadı!", "DefaultErrorMessage404": "Kaynak bulunamadı!",
"DefaultErrorMessage404Detail": "İstenilen kaynak sunucuda bulunamadı.", "DefaultErrorMessage404Detail": "İstenilen kaynak sunucuda bulunamadı.",
"EntityNotFoundErrorMessage": "Id değeri {1} olan {0} türünden bir nesne bulunamadı!", "EntityNotFoundErrorMessage": "Id değeri {1} olan {0} türünden bir nesne bulunamadı!",
"AbpDbConcurrencyErrorMessage": "Gönderdiğiniz veri başka bir kullanıcı/istemci tarafından değiştirilmiş. Lütfen işlemi iptal edip baştan deneyin.",
"Error": "Hata", "Error": "Hata",
"UnhandledException": "Yakalanmamış hata!", "UnhandledException": "Yakalanmamış hata!",
"401Message": "Yetkisiz İşlem", "401Message": "Yetkisiz İşlem",

Loading…
Cancel
Save