Levge.Exceptions 2.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Levge.Exceptions --version 2.2.0
                    
NuGet\Install-Package Levge.Exceptions -Version 2.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Levge.Exceptions" Version="2.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Levge.Exceptions" Version="2.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Levge.Exceptions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Levge.Exceptions --version 2.2.0
                    
#r "nuget: Levge.Exceptions, 2.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Levge.Exceptions@2.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Levge.Exceptions&version=2.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Levge.Exceptions&version=2.2.0
                    
Install as a Cake Tool

Publish NuGet Package

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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