Tooark.Exceptions
3.3.6
See the version list below for details.
dotnet add package Tooark.Exceptions --version 3.3.6
NuGet\Install-Package Tooark.Exceptions -Version 3.3.6
<PackageReference Include="Tooark.Exceptions" Version="3.3.6" />
<PackageVersion Include="Tooark.Exceptions" Version="3.3.6" />
<PackageReference Include="Tooark.Exceptions" />
paket add Tooark.Exceptions --version 3.3.6
#r "nuget: Tooark.Exceptions, 3.3.6"
#:package Tooark.Exceptions@3.3.6
#addin nuget:?package=Tooark.Exceptions&version=3.3.6
#tool nuget:?package=Tooark.Exceptions&version=3.3.6
Tooark.Exceptions
Biblioteca que fornece exceções padronizadas para projetos .NET, com mapeamento para status HTTP e suporte a múltiplas formas de construção de mensagens de erro.
Conteúdo
- Visão Geral
- Recursos Suportados
- Exceções Disponíveis
- Exemplos de Uso
- Dependências
- Contribuição
- Licença
Visão Geral
Todas as exceções específicas do pacote herdam de TooarkException, que por sua vez herda de Exception.
A classe base concentra:
- armazenamento de mensagens de erro (
GetErrorMessages()); - armazenamento de notificações (
GetNotifications()); - contrato para código HTTP (
GetStatusCode()).
Recursos Suportados
As classes de exceção suportam os seguintes construtores:
ExceptionType(string message)ExceptionType(IList<string> messages)ExceptionType(Notification notification)ExceptionType(string messageFormat, params object[] args)
Novos recursos documentados
- Mensagem formatada com placeholders: permite criar mensagens dinâmicas com
string.Format. - Integração com
Notification: reutiliza mensagens/notificações já agregadas na camada de validação. - Múltiplas mensagens: suporta lista de erros para cenários de validação com mais de uma falha.
Exceções Disponíveis
| Classe | Status HTTP |
|---|---|
BadRequestException |
400 (BadRequest) |
GetInfoException |
400 (BadRequest) |
UnauthorizedException |
401 (Unauthorized) |
ForbiddenException |
403 (Forbidden) |
NotFoundException |
404 (NotFound) |
MethodNotAllowedException |
405 (MethodNotAllowed) |
ConflictException |
409 (Conflict) |
PayloadTooLargeException |
413 (PayloadTooLarge) |
UnsupportedMediaTypeException |
415 (UnsupportedMediaType) |
UnprocessableEntityException |
422 (UnprocessableEntity) |
TooManyRequestsException |
429 (TooManyRequests) |
InternalServerErrorException |
500 (InternalServerError) |
BadGatewayException |
502 (BadGateway) |
ServiceUnavailableException |
503 (ServiceUnavailable) |
GatewayTimeoutException |
504 (GatewayTimeout) |
Exemplos de Uso
1) Mensagem simples
throw new BadRequestException("Payload inválido.");
2) Múltiplas mensagens
throw new BadRequestException([
"Nome é obrigatório.",
"E-mail inválido."
]);
3) Mensagem formatada (novo)
var userId = 42;
throw new NotFoundException("Usuário com ID {0} não encontrado.", userId);
4) A partir de Notification (novo)
using Tooark.Notifications;
public sealed class DomainNotification : Notification { }
var notification = new DomainNotification();
notification.AddNotification("Documento é obrigatório.", "Document");
notification.AddNotification("Telefone inválido.", "Phone");
throw new BadRequestException(notification);
5) Tratamento padronizado
using Tooark.Exceptions;
try
{
throw new ServiceUnavailableException("Serviço externo indisponível.");
}
catch (TooarkException ex)
{
var statusCode = ex.GetStatusCode();
var errors = ex.GetErrorMessages();
var notifications = ex.GetNotifications();
Console.WriteLine($"Status: {(int)statusCode} - {statusCode}");
Console.WriteLine($"Primeiro erro: {errors.FirstOrDefault()}");
Console.WriteLine($"Total de notificações: {notifications.Count}");
}
6) Conflito de estado (409)
throw new ConflictException("Já existe um usuário com este e-mail.");
7) Payload muito grande (413)
throw new PayloadTooLargeException(
"Arquivo excede o limite permitido de {0} MB.",
10
);
8) Tipo de mídia não suportado (415)
throw new UnsupportedMediaTypeException("Content-Type 'text/plain' não é suportado.");
9) Entidade não processável (422)
throw new UnprocessableEntityException([
"CPF inválido para a regra de negócio.",
"Data de nascimento incompatível com o cadastro."
]);
10) Muitas requisições (429)
throw new TooManyRequestsException("Limite de requisições excedido. Tente novamente em alguns segundos.");
Dependências
Contribuição
Contribuições são bem-vindas! Sinta-se à vontade para abrir issues e pull requests no repositório Tooark.
Licença
Este projeto está licenciado sob a licença BSD 3-Clause. Veja LICENSE para mais detalhes.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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
- Microsoft.AspNetCore.Http (>= 2.3.12)
- Microsoft.AspNetCore.Mvc (>= 2.3.12)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.12)
- Microsoft.Extensions.Caching.Memory (>= 10.0.11)
- Microsoft.Extensions.DependencyInjection (>= 10.0.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Microsoft.Extensions.FileProviders.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Localization (>= 10.0.11)
- Microsoft.Extensions.Options (>= 10.0.11)
- System.Security.Cryptography.Xml (>= 10.0.11)
- Tooark.Notifications (>= 3.3.6)
-
net8.0
- Microsoft.AspNetCore.Http (>= 2.3.12)
- Microsoft.AspNetCore.Mvc (>= 2.3.12)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.12)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.FileProviders.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Localization (>= 8.0.30)
- Microsoft.Extensions.Options (>= 8.0.2)
- System.Security.Cryptography.Xml (>= 8.0.4)
- Tooark.Notifications (>= 3.3.6)
NuGet packages (15)
Showing the top 5 NuGet packages that depend on Tooark.Exceptions:
| Package | Downloads |
|---|---|
|
Tooark.Utils
General utility package for .NET applications. |
|
|
Tooark.Enums
Package for creating validated enumerators for .NET applications. |
|
|
Tooark.ValueObjects
Package for managing predefined and validated Value Objects for .NET applications. |
|
|
Tooark.Entities
Package for managing base entities in .NET applications. |
|
|
Tooark.Attributes
Package for creating attribute validators for .NET applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.7.1 | 0 | 10/17/2026 |
| 4.7.0 | 568 | 9/30/2026 |
| 4.6.0 | 328 | 9/29/2026 |
| 4.5.0 | 309 | 9/29/2026 |
| 4.4.0 | 305 | 9/28/2026 |
| 4.3.0 | 312 | 9/26/2026 |
| 4.2.1 | 303 | 9/25/2026 |
| 4.2.0 | 330 | 9/20/2026 |
| 4.1.0 | 303 | 9/18/2026 |
| 4.0.1 | 367 | 8/25/2026 |
| 4.0.0 | 372 | 8/25/2026 |
| 3.3.6 | 219 | 9/18/2026 |
| 3.3.5 | 254 | 8/25/2026 |
| 3.3.4 | 431 | 8/12/2026 |
| 3.3.3 | 529 | 7/27/2026 |
| 3.3.2 | 531 | 6/11/2026 |
| 3.3.1 | 316 | 6/6/2026 |
| 2.3.5 | 178 | 9/18/2026 |
| 2.3.4 | 207 | 8/25/2026 |
| 2.3.3 | 235 | 7/27/2026 |