Levge.Exceptions
2.1.0
See the version list below for details.
dotnet add package Levge.Exceptions --version 2.1.0
NuGet\Install-Package Levge.Exceptions -Version 2.1.0
<PackageReference Include="Levge.Exceptions" Version="2.1.0" />
<PackageVersion Include="Levge.Exceptions" Version="2.1.0" />
<PackageReference Include="Levge.Exceptions" />
paket add Levge.Exceptions --version 2.1.0
#r "nuget: Levge.Exceptions, 2.1.0"
#:package Levge.Exceptions@2.1.0
#addin nuget:?package=Levge.Exceptions&version=2.1.0
#tool nuget:?package=Levge.Exceptions&version=2.1.0
Levge.Exceptions
Levge projelerinde kullanılmak üzere özel exception tiplerini içeren bir pakettir. HTTP semantiğine uygun, tutarlı ve anlamlı hata yönetimi sağlar.
Kurulum
dotnet add package Levge.Exceptions
Exception Listesi
| Sınıf | HTTP | ErrorCode | Açıklama |
|---|---|---|---|
LevgeException |
— | — | Tüm Levge exception'larının base sınıfı |
LevgeNotFoundException |
404 | NOT_FOUND |
Kayıt bulunamadı |
LevgeUnauthorizedException |
401 | UNAUTHORIZED |
Kimlik doğrulaması yapılmamış |
LevgeForbiddenException |
403 | FORBIDDEN |
Yetkisiz erişim |
LevgeConflictException |
409 | CONFLICT |
Kayıt zaten mevcut |
LevgeBadRequestException |
400 | BAD_REQUEST |
Genel geçersiz istek |
LevgeValidationException |
400 | VALIDATION_ERROR |
FluentValidation hataları, alan bazlı |
LevgeBusinessRuleException |
422 | özelleştirilebilir | İş kuralı ihlali |
LevgeTenantException |
400/403 | TENANT_NOT_FOUND / TENANT_ACCESS_DENIED |
Tenant bulunamadı veya erişim reddedildi |
LevgeLicenseException |
403 | LICENSE_INVALID / LICENSE_DEVICE_LIMIT_EXCEEDED |
Lisans geçersiz veya cihaz limiti aşıldı |
LevgeExternalServiceException |
502 | EXTERNAL_SERVICE_ERROR |
Dış servis hatası |
Kullanım
Base — LevgeException
Tüm Levge exception'larının türevidir. StatusCode ve ErrorCode property'lerini taşır.
throw new LevgeException(500, "Beklenmeyen bir hata oluştu.", "INTERNAL_ERROR");
// StatusCode ve ErrorCode okuma
catch (LevgeException ex)
{
Console.WriteLine(ex.StatusCode); // 500
Console.WriteLine(ex.ErrorCode); // "INTERNAL_ERROR"
}
HTTP — NotFoundException
throw new LevgeNotFoundException("Kullanıcı bulunamadı.");
// Alan adıyla birlikte
throw new LevgeNotFoundException("UserId", "Kullanıcı bulunamadı.");
HTTP — UnauthorizedException
throw new LevgeUnauthorizedException();
// veya
throw new LevgeUnauthorizedException("Oturumunuz sona erdi.");
HTTP — ForbiddenException
throw new LevgeForbiddenException();
// veya
throw new LevgeForbiddenException("Bu kaynağa erişim yetkiniz yok.");
HTTP — ConflictException
throw new LevgeConflictException("Bu kayıt zaten mevcut.");
// Alan adıyla birlikte
throw new LevgeConflictException("Email", "Bu e-posta adresi zaten kullanılıyor.");
HTTP — BadRequestException
throw new LevgeBadRequestException("Gönderilen istek geçersiz.");
Validation — ValidationException
// Tek alan
throw new LevgeValidationException("Email", "Geçerli bir e-posta adresi giriniz.");
// Çoklu alan (FluentValidation entegrasyonu)
var errors = new Dictionary<string, string[]>
{
{ "Email", ["E-posta zorunludur.", "Geçersiz format."] },
{ "Password", ["Şifre en az 8 karakter olmalıdır."] }
};
throw new LevgeValidationException(errors);
// Errors dictionary'sine erişim
catch (LevgeValidationException ex)
{
foreach (var (field, messages) in ex.Errors)
Console.WriteLine($"{field}: {string.Join(", ", messages)}");
}
Domain — BusinessRuleException
throw new LevgeBusinessRuleException("Bakiye yetersiz.");
// Özel kural koduyla
throw new LevgeBusinessRuleException("INSUFFICIENT_BALANCE", "Bakiye yetersiz.");
// RuleCode okuma
catch (LevgeBusinessRuleException ex)
{
Console.WriteLine(ex.RuleCode); // "INSUFFICIENT_BALANCE"
}
Domain — TenantException
// Tenant bulunamadı (400)
throw new LevgeTenantException("Tenant bulunamadı.");
// Tenant erişimi reddedildi (403) — static factory
throw LevgeTenantException.AccessDenied();
throw LevgeTenantException.AccessDenied("Bu tenant'a erişim izniniz yok.");
Domain — LicenseException
// Lisans geçersiz (403)
throw new LevgeLicenseException("Lisansınız geçersiz veya süresi dolmuş.");
// Özel hata koduyla
throw new LevgeLicenseException("LICENSE_EXPIRED", "Lisans süresi dolmuş.");
// Cihaz limiti aşıldı — static factory
throw LevgeLicenseException.DeviceLimitExceeded();
throw LevgeLicenseException.DeviceLimitExceeded("Maksimum cihaz limitine ulaştınız.");
Teknik — ExternalServiceException
throw new LevgeExternalServiceException("Stripe", "Ödeme servisi yanıt vermedi.");
// InnerException ile
catch (HttpRequestException ex)
{
throw new LevgeExternalServiceException("Iyzico", "Ödeme işlemi başarısız.", ex);
}
// ServiceName okuma
catch (LevgeExternalServiceException ex)
{
Console.WriteLine(ex.ServiceName); // "Stripe"
}
Global Exception Handler ile Kullanım
Bu exception'lar, Levge.ConsistentResponse paketindeki GlobalExceptionMiddleware ile otomatik olarak yakalanıp StatusCode değerine göre HTTP yanıtlarına dönüştürülür.
Hedef Framework
net8.0 ve net9.0 desteklenir.
Lisans
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Levge.Exceptions:
| Package | Downloads |
|---|---|
|
Levge.Domain
Domain entity, interface, enumeration, domain events, and Result pattern base types for Levge projects. |
|
|
Levge.ConsistentResponse
A library for standardizing API responses in ASP.NET Core applications with consistent formatting, error handling, and exception middleware. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.3.0 | 195 | 4/29/2026 |
| 2.2.0 | 94 | 4/29/2026 |
| 2.1.0 | 165 | 4/27/2026 |
| 2.0.1 | 178 | 4/27/2026 |
| 2.0.0 | 118 | 4/26/2026 |
| 1.1.45 | 221 | 1/22/2026 |
| 1.1.43 | 624 | 6/24/2025 |
| 1.1.42 | 236 | 6/24/2025 |
| 1.1.41 | 407 | 6/22/2025 |
| 1.1.31 | 172 | 6/21/2025 |
| 1.1.1 | 183 | 6/21/2025 |
| 1.1.0 | 681 | 6/17/2025 |
| 1.0.1 | 298 | 6/17/2025 |
| 1.0.0 | 419 | 6/16/2025 |