From 3612ca88c9c120760a046dd44d5fb6e4584a9df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 30 Apr 2018 00:22:36 +0300 Subject: [PATCH] Rename AbpLoggerExtensions --- docs/Exception-Handling.md | 25 +++++++++++++------ ...erExtensions.cs => AbpLoggerExtensions.cs} | 2 +- .../Volo/Abp/BusinessException.cs | 7 +++++- .../Volo/Abp/IBusinessException.cs | 6 ++--- 4 files changed, 26 insertions(+), 14 deletions(-) rename src/Volo.Abp.Core/Microsoft/Extensions/Logging/{LoggerExtensions.cs => AbpLoggerExtensions.cs} (98%) diff --git a/docs/Exception-Handling.md b/docs/Exception-Handling.md index 23586965ef..344447932a 100644 --- a/docs/Exception-Handling.md +++ b/docs/Exception-Handling.md @@ -3,7 +3,7 @@ ABP provides a built-in infrastructure and offers a standard model to exception handling for a web application. * Automatically **handles all exceptions** and sends a standard **formatted error message** to the client for an API/AJAX request. -* Automatically hides **internal infrastructure errors**. +* Automatically hides **internal infrastructure errors** and returns a standard error message. * Provides configuration option to **localize** exception messages. * Automatically maps standard exceptions to **HTTP status codes** and provides configuration option to map custom exceptions. @@ -85,7 +85,7 @@ Error **details** in an optional field of the JSON error message. Thrown `Except #### Logging -Caught exceptions are automatically logged. +Caught exceptions are automatically logged. ##### Log Level @@ -114,16 +114,25 @@ public class MyException : Exception, IExceptionWithSelfLogging } ```` +> `ILogger.LogException` extension methods is used to write exception logs. You can use the same extension method when needed. +### Conventional Exception Classes -TODO: +There are some **conventional** exception classes you can **directly throw** or **derive** your own exception types when needed. -Exception Interfaces (IHasLogLevel, ICanLogDetails, IHasErrorCode... etc.) +* `BusinessException`: Indicates a business exception (rather than infrastructure exceptions). You can instead implement the `IBusinessException` interface. +* `UserFriendlyException`: Indicates an exception that can be **directly shown to the user** (without hiding or localizing). You can instead implement the `IUserFriendlyException` interface. -Pre-Defined Base Exception Classes +### Built-In Exceptions -Standard Exception classes (AbpValidationException) +Some exception types are automatically thrown by the framework. -Exception Localization +* `AbpAuthorizationException` is thrown if the current user has no permission to perform the requested operation. See authorization document (TODO: link) for more. +* `AbpValidationException` is thrown if the input of the current request is not valid. See validation document (TODO: link) for more. +* `EntityNotFoundException` is thrown if the requested entity is not available. This is mostly thrown by [repositories](Repositories.md). -HTTP Status Code Mapping \ No newline at end of file +You can also throw these type of exceptions in your code (while it's rarely needed). + +### Exception Localization + +### HTTP Status Code Mapping \ No newline at end of file diff --git a/src/Volo.Abp.Core/Microsoft/Extensions/Logging/LoggerExtensions.cs b/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs similarity index 98% rename from src/Volo.Abp.Core/Microsoft/Extensions/Logging/LoggerExtensions.cs rename to src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs index 4a75164486..2011480332 100644 --- a/src/Volo.Abp.Core/Microsoft/Extensions/Logging/LoggerExtensions.cs +++ b/src/Volo.Abp.Core/Microsoft/Extensions/Logging/AbpLoggerExtensions.cs @@ -4,7 +4,7 @@ using Volo.Abp.Logging; namespace Microsoft.Extensions.Logging { - public static class LoggerExtensions + public static class AbpLoggerExtensions { public static void LogWithLevel(this ILogger logger, LogLevel logLevel, string message) { diff --git a/src/Volo.Abp.Core/Volo/Abp/BusinessException.cs b/src/Volo.Abp.Core/Volo/Abp/BusinessException.cs index 1968fea1ee..a47659cf2a 100644 --- a/src/Volo.Abp.Core/Volo/Abp/BusinessException.cs +++ b/src/Volo.Abp.Core/Volo/Abp/BusinessException.cs @@ -6,7 +6,12 @@ using Volo.Abp.Logging; namespace Volo.Abp { - public class BusinessException : Exception, IBusinessException, IHasErrorDetails, IHasLogLevel + [Serializable] + public class BusinessException : Exception, + IBusinessException, + IHasErrorCode, + IHasErrorDetails, + IHasLogLevel { public string Code { get; set; } diff --git a/src/Volo.Abp.Core/Volo/Abp/IBusinessException.cs b/src/Volo.Abp.Core/Volo/Abp/IBusinessException.cs index c7fcf8b502..449d4e92a7 100644 --- a/src/Volo.Abp.Core/Volo/Abp/IBusinessException.cs +++ b/src/Volo.Abp.Core/Volo/Abp/IBusinessException.cs @@ -1,8 +1,6 @@ -using Volo.Abp.ExceptionHandling; - -namespace Volo.Abp +namespace Volo.Abp { - public interface IBusinessException : IHasErrorCode + public interface IBusinessException { }