abp-exception-handling
/abp-exception-handling
ABP Framework v10.x (10.4–10.6) exception handling: BusinessException, UserFriendlyException, RemoteServiceErrorResponse, HTTP status mapping, error code localization. Use for error handling in ABP, when you need a business exception or an HTTP error response.
- Author
- burakdmir ↗
- Repository
- abp-skills ↗
- Licence
- MIT
- Last repository change
- 14.08.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 14.08.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
ABP Framework v10.x (10.4–10.6) exception handling: BusinessException, UserFriendlyException, RemoteServiceErrorResponse, HTTP status mapping, error code localization. Use for error handling in ABP, when you need a business exception or an HTTP error response.
Original author description
ABP Framework v10.x (10.4–10.6) exception handling: BusinessException, UserFriendlyException, RemoteServiceErrorResponse, HTTP status mapping, error code localization. Use for error handling in ABP, when you need a business exception or an HTTP error response.
How it works
- Trigger
- Core Concepts
- Error Message Format
- Business Exceptions
- HTTP Status Code Mapping
- Logging
- Exception Handling Options
- Best Practices
- Common Patterns
- Exception Flow
SKILL.md preview
---
name: abp-exception-handling
description: "ABP Framework v10.x (10.4–10.6) exception handling: BusinessException, UserFriendlyException, RemoteServiceErrorResponse, HTTP status mapping, error code localization. Use for error handling in ABP, when you need a business exception or an HTTP error response."
---
# ABP Exception Handling Skill
## Trigger
User asks about exception handling, error handling, RemoteServiceErrorResponse, error codes, business exceptions, HTTP status mapping, self-logging exceptions, or API error responses in ABP Framework.
---
## Core Concepts
ABP provides a built-in exception handling infrastructure that:
- **Automatically handles all exceptions** and sends standardized error messages for API/AJAX requests
- **Hides internal infrastructure errors** and returns safe error messages
- **Maps standard exceptions to HTTP status codes**
- **Supports localized exception messages**
- **Provides configurable custom exception mapping**
---
## Error Message Format
All API errors return a `RemoteServiceErrorResponse` JSON:
### Basic Error
```json
{
"error": {
"message": "This topic is locked and can not add a new message"
}
}
```
### Error with Code
```json
{
"error": {
"code": "App:010046",
"message": "An error occurred while processing your request."
}
}
```
Implement `IHasErrorCode` to include error codes:
```csharp
public class MyBusinessException : Exception, IHasErrorCode
{
public string Code => "App:010046";
}
```
### Error with Details
```json
{
"error": {
"code": "App:010046",
"message": "Something went wrong.",
"details": "Stack trace or additional context..."
}
}
```
Implement `IHasErrorDetails` to include details:
```csharp
public class MyException : Exception, IHasErrorDetails
{
public string Details => "Additional diagnostic information...";
}
```
### Validation Errors
```json
{
"error": {
"code": "App:010046",
"message": "Your request is not valid, please correct and try again!",
"validationErrors": [
{
"message": "Username should be minimum length of 3.",
"members": ["userName"]
},
{
"message": "Password is required",
"members": ["password"]
}
]
}
}
```
`AbpValidationException` implements `IHasValidationErrors` and is auto-thrown on invalid input.
---
## Business Exceptions
### Creating Custom Business Exceptions
```csharp
public class BookNotFoundException : Exception
{
public Guid BookId { get; }
public BookNotFoundException(Guid bookId)
: base($"Book not found with id: {bookId}")
{
BookId = bookId;
}
}
```
### With Error Code
```csharp
public class InsufficientStockException : Exception, IHasErrorCode
{
public string Code => "BookStore:010001";
public InsufficientStockException(string message) : base(message) { }
}
```
### With Localized Message
```csharp
public class UserFriendlyException : Exception
{
public UserFriendlyException(
string message,
string details = null,
string code = null
) : base(message) { }
}
```
Use localization resource:
```csharp
throw new UserFriendlyException(
L["ErrorMessage:InsufficientStock"]
);
```
---
## HTTP Status Code Mapping
ABP automatically maps exceptions to HTTP status codes:
| Exception Type | HTTP Status |
|---|---|
| `AbpValidationException` | 400 Bad Request |
| `AbpAuthorizationException` | 403 Forbidden |
| `EntityNotFoundException` | 404 Not Found |
| `UserFriendlyException` | 400 Bad Request |
| `EntityAlreadyExistsException` | 409 Conflict |
| `NonImplementException` | 501 Not Implemented |
| Generic `Exception` | 500 Internal Server Error |
### Custom Exception Mapping
```csharp
Configure<AbpExceptionHandlingOptions>(options =>
{
options.MapToStatusCode<MyCustomException>(StatusCodes.Status409Conflict);
});
```
---
## Logging
### Automatic Logging
Caught exceptions are automatically logged by ABP.
### Log Level Control
Implement `IHasLogLevel` to control the log level:
```csharp
public class MyExpectedException : Exception, IHasLogLevel
{
public LogLevel LogLevel => LogLevel.Warning;
public MyExpectedException(string message) : base(message) { }
}
```
Default log levels:
- `AbpValidationException` → `Warning`
- `AbpAuthorizationException` → `Warning`
- `UserFriendlyException` → `Warning`
- Generic `Exception` → `Error`
### Self-Logging Exceptions
Exceptions can write additional logs by implementing `IExceptionWithSelfLogging`:
```csharp
public class MyException : Exception, IExceptionWithSelfLogging
{
public void Log(ILogger logger)
{
logger.LogWarning("Additional context: {ContextData}", SomeData);
}
}
```
Use `ILogger.LogException` extension method for manual logging:
```csharp
logger.LogException(myException);
```
---
## Exception Handling Options
```csharp
Configure<AbpExceptionHandlingOptions>(options =>
{
// Send exception details to client (development only!)
options.SendExceptionsDetailsToClients = true;
// Include stack trace in response (development only!)
options.IncludeStackTraceInExceptionDetails = true;
// Custom exception mappers
options.MapToStatusCode<MyException>(StatusCodes.Status409Conflict);
});
```
> **Warning:** Never enable `SendExceptionsDetailsToClients` or `IncludeStackTraceInExceptionDetails` in production — they expose internal implementation details.
---
## Best Practices
1. **Use `UserFriendlyException`** for errors that should be shown directly to users
2. **Implement `IHasErrorCode`** for machine-readable error codes (client-side handling)
3. **Implement `IHasLogLevel`** to control noise in logs (expected errors = Warning)
4. **Implement `IExceptionWithSelfLogging`** for exceptions that need additional context logged
5. **Map custom exceptions to HTTP status codes** using `AbpExceptionHandlingOptions`
6. **Localize error messages** for multi-language support
7. **Never expose stack traces** in production
8. **Use specific exception types** for different error scenarios (not generic `Exception`)
9. **Let ABP handle exceptions** — don't catch and re-throw unless adding context
10. **Use `EntityNotFoundException`** for missing entities (auto-mapped to 404)
---
## Common Patterns
### Application Service Error Handling
```csharp
public class BookAppService : ApplicationService
{
public async Task<BookDto> GetAsync(Guid id)
{
var book = await _bookRepository.FindAsync(id);
if (book == null)
{
throw new EntityNotFoundException(typeof(Book), id);
}
return ObjectMapper.Map<Book, BookDto>(book);
}
}
```
### Business Rule Violation
```csharp
public class InsufficientStockException : Exception, IHasErrorCode
{
public string Code => "BookStore:010001";
public int RequestedQuantity { get; }
public int AvailableQuantity { get; }
public InsufficientStockException(int requested, int available)
: base($"Requested {requested} but only {available} available")
{
RequestedQuantity = requested;
AvailableQuantity = available;
}
}
```
### Client-Side Error Handling
```typescript
try {
await bookService.create(input);
} catch (error) {
if (error.response?.data?.error?.code === 'BookStore:010001') {
// Handle insufficient stock
showStockWarning(error.response.data.error.validationErrors);
}
}
```
---
## Exception Flow
```
Request arrives
↓
ABP handles request
↓
Exception thrown
↓
ABP Exception Handler intercepts
↓
Determines HTTP status code
↓
Logs exception (respects IHasLogLevel)
↓
Calls IExceptionWithSelfLogging.Log() if implemented
↓
Builds RemoteServiceErrorResponse
↓
Returns HTTP response with error JSON
```
---
## Related
- [Validation](./validation.md) — AbpValidationException and validation errors
- [Audit Logging](./audit-logging.md) — Exceptions are logged in audit trail
- [Logging](./logging.md) — ASP.NET Core logging infrastructure
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · burakdmir/abp-skills | 100 | MIT |
| burakdmir/abp-skills | 100 | MIT |
Database snapshot: 13.11.2026 · package version ff2a5309ba91 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Similar skills
- 100handle-validation-and-errors
Validates DTOs/inputs and throws/localizes business errors in an ABP app. USE FOR: data annotations, IValidationEnabled, FluentValidation, BusinessException/UserFriendlyException, error codes, localizing error messages, mapping exceptions to HTTP status codes. DO NOT USE FOR:… - 100abp-localization
ABP Framework v10.x (10.4–10.6) localization: localization resource, JSON files, culture fallback, L[] helper, IStringLocalizer. Use for multi-language, localization, or translation in ABP. - 100abp-localization
ABP Framework v10.x (10.4–10.6) localization: localization resource, JSON files, culture fallback, L[] helper, IStringLocalizer. Use for multi-language, localization, or translation in ABP. - 100php-error-handling
Implement modern PHP error and exception handling patterns. Use when implementing exception hierarchies, error handlers, or custom exceptions in PHP. - 100problem-details-rfc9457
Use when generating error responses, exception listeners, or custom exceptions in a Symfony API. Defines RFC 9457 (problem+json) error format, mapping domain exceptions to HTTP status codes, and a single kernel exception listener. Use when the task mentions error handling,… - 100python-error-handling
Python error handling patterns including input validation, exception hierarchies, and partial failure handling. Use when implementing validation logic, designing exception strategies, handling batch processing failures, or building robust APIs.