From fe36ede55bcd6b525d0b7c1cb7d43f0861e0ec44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 27 Apr 2018 21:51:11 +0300 Subject: [PATCH] Minor refactoring --- .../DefaultExceptionToErrorInfoConverter.cs | 15 +++------------ src/Volo.Abp.Core/Volo/Abp/BusinessException.cs | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs index 65ece43094..3edfa66cba 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs @@ -98,13 +98,13 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling protected virtual void TryToLocalizeExceptionMessage(Exception exception, RemoteServiceErrorInfo errorInfo) { - //TODO: For test purpose if (!(exception is IHasErrorCode exceptionWithErrorCode)) { return; } - if (!exceptionWithErrorCode.Code.Contains(":")) + if (exceptionWithErrorCode.Code.IsNullOrWhiteSpace() || + !exceptionWithErrorCode.Code.Contains(":")) { return; } @@ -119,7 +119,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling var stringLocalizer = _stringLocalizerFactory.Create(localizationResourceType); var localizedString = stringLocalizer[exceptionWithErrorCode.Code]; - if (localizedString.ResourceNotFound) + if (!localizedString.ResourceNotFound) { return; } @@ -268,15 +268,6 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling protected virtual string L(string name) { //TODO: Localization? - //try - //{ - // return _localizationManager.GetString(AbpWebConsts.LocalizaionSourceName, name); - //} - //catch (Exception) - //{ - // return name; - //} - return name; } } diff --git a/src/Volo.Abp.Core/Volo/Abp/BusinessException.cs b/src/Volo.Abp.Core/Volo/Abp/BusinessException.cs index ae3d8efca9..fbf1595fe0 100644 --- a/src/Volo.Abp.Core/Volo/Abp/BusinessException.cs +++ b/src/Volo.Abp.Core/Volo/Abp/BusinessException.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.Serialization; using Microsoft.Extensions.Logging; using Volo.Abp.ExceptionHandling; using Volo.Abp.Logging; @@ -13,18 +14,25 @@ namespace Volo.Abp public LogLevel LogLevel { get; set; } = LogLevel.Warning; - public override string Message => base.Message ?? Code; - public BusinessException() { } - public BusinessException(string code, string message = null, string details = null) - : base(message) + public BusinessException(string code = null, string message = null, string details = null, Exception innerException = null) + : base(message, innerException) { Code = code; Details = details; } + + /// + /// Constructor for serializing. + /// + public BusinessException(SerializationInfo serializationInfo, StreamingContext context) + : base(serializationInfo, context) + { + + } } } \ No newline at end of file