Browse Source

Minor refactoring

pull/279/head
Halil İbrahim Kalkan 9 years ago
parent
commit
fe36ede55b
  1. 15
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/DefaultExceptionToErrorInfoConverter.cs
  2. 16
      src/Volo.Abp.Core/Volo/Abp/BusinessException.cs

15
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) protected virtual void TryToLocalizeExceptionMessage(Exception exception, RemoteServiceErrorInfo errorInfo)
{ {
//TODO: For test purpose
if (!(exception is IHasErrorCode exceptionWithErrorCode)) if (!(exception is IHasErrorCode exceptionWithErrorCode))
{ {
return; return;
} }
if (!exceptionWithErrorCode.Code.Contains(":")) if (exceptionWithErrorCode.Code.IsNullOrWhiteSpace() ||
!exceptionWithErrorCode.Code.Contains(":"))
{ {
return; return;
} }
@ -119,7 +119,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
var stringLocalizer = _stringLocalizerFactory.Create(localizationResourceType); var stringLocalizer = _stringLocalizerFactory.Create(localizationResourceType);
var localizedString = stringLocalizer[exceptionWithErrorCode.Code]; var localizedString = stringLocalizer[exceptionWithErrorCode.Code];
if (localizedString.ResourceNotFound) if (!localizedString.ResourceNotFound)
{ {
return; return;
} }
@ -268,15 +268,6 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling
protected virtual string L(string name) protected virtual string L(string name)
{ {
//TODO: Localization? //TODO: Localization?
//try
//{
// return _localizationManager.GetString(AbpWebConsts.LocalizaionSourceName, name);
//}
//catch (Exception)
//{
// return name;
//}
return name; return name;
} }
} }

16
src/Volo.Abp.Core/Volo/Abp/BusinessException.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Runtime.Serialization;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Volo.Abp.ExceptionHandling; using Volo.Abp.ExceptionHandling;
using Volo.Abp.Logging; using Volo.Abp.Logging;
@ -13,18 +14,25 @@ namespace Volo.Abp
public LogLevel LogLevel { get; set; } = LogLevel.Warning; public LogLevel LogLevel { get; set; } = LogLevel.Warning;
public override string Message => base.Message ?? Code;
public BusinessException() public BusinessException()
{ {
} }
public BusinessException(string code, string message = null, string details = null) public BusinessException(string code = null, string message = null, string details = null, Exception innerException = null)
: base(message) : base(message, innerException)
{ {
Code = code; Code = code;
Details = details; Details = details;
} }
/// <summary>
/// Constructor for serializing.
/// </summary>
public BusinessException(SerializationInfo serializationInfo, StreamingContext context)
: base(serializationInfo, context)
{
}
} }
} }
Loading…
Cancel
Save