Eiding.ExceptionManager
0.2.0
See the version list below for details.
dotnet add package Eiding.ExceptionManager --version 0.2.0
NuGet\Install-Package Eiding.ExceptionManager -Version 0.2.0
<PackageReference Include="Eiding.ExceptionManager" Version="0.2.0" />
paket add Eiding.ExceptionManager --version 0.2.0
#r "nuget: Eiding.ExceptionManager, 0.2.0"
// Install Eiding.ExceptionManager as a Cake Addin #addin nuget:?package=Eiding.ExceptionManager&version=0.2.0 // Install Eiding.ExceptionManager as a Cake Tool #tool nuget:?package=Eiding.ExceptionManager&version=0.2.0
ExceptionManager for ASP .NET Core API
Project is in developement
- How to use
- Exceptions 2.1. How to use 2.2 Custom exceptions
- Custom exception messages 3.1. How to use 3.2 Custom exception messages
1. How to use
Add reference to ExeptionManager in Program.cs
<b>using</b> Eiding.ExeptionManager;
Paste below code snippet under builder
builder.Services.AddControllersWithViews(options ⇒ options.Filters.Add< ExceptionFilter>();
Use custom exceptions from ExceptionManager ( or crete you own )
2. Exceptions
Every exception must inherit from <b>Exception</b>, and Eiding.ExeptionManager.<b>IExceptionProvider</b>
You can find exceptions there: <b>using</b> Eiding.ExceptionManager.Exceptions;
2.1. How to use
You have <b>three</b> different ways to use exceptions:
2.1.1 Classic way
throw new Exception("Error message);
2.1.2 Static methods ( every exception has its own methods )
Exception.Throw("Error message);
2.1.3 StatusCodeManager
Import manager from:
using Eiding.ExceptionManager.Managers;
Type <b>StatusCodeManager.</b> and choose which StatusCode you need (sc*)
StatusCodeManager.sc400.
Now you have access to every method from custom exception that represents StatusCode that you've choosed
StatusCodeManager.sc400.Throw("test");
2.2. Custom exceptions
2.2.1 InvalidArgumentException ( 400 )
Inherit from: ArgumentException, IExceptionProvider
Constructor
InvalidArgumentException(string? message = "Parameter is invalid.", string? paramName = null)
Methods
If <b>message</b> in any method is null, exception throws with default message <b>"Parameter is invalid."</b>
Throw()
Throws an <b>InvalidArgumentException</b>.
Throw(string? message = null, string? paramName = null)
IfNull()
Throws an <b>InvalidArgumentException</b> if argument is null.
IfNull(object? argument, string? message = null, string? paramName = null)
Throws an <b>InvalidArgumentException</b> if argument is null or empty string.
IfNull(string? argument, string? message = null, string? paramName = null)
Throws an <b>InvalidArgumentException</b> if argument is null or it's a list of null objects.
IfNull(IEnumerable<object?>? argument, string? message = null, string? paramName = null)
IfTrue()
Throws an <b>InvalidArgumentException</b> if condition it true.
IfTrue(bool conditions, string? message = null, string? paramName = null)
IfZero()
Throws an <b>InvalidArgumentException</b> if number equals 0.
IfZero(int number, string? message = null, string? paramName = null)
Throws an <b>InvalidArgumentException</b> if number equals 0d.
IfZero(double number, string? message = null, string? paramName = null)
Throws an <b>InvalidArgumentException</b> if number equals 0f.
IfZero(float number, string? message = null, string? paramName = null)
IfSmallerThanZero()
Throws an <b>InvalidArgumentException</b> if number is smaller than 0.
IfSmallerThanZero(int number, string? message = null, string? paramName = null)
Throws an <b>InvalidArgumentException</b> if number is smaller than 0d.
IfSmallerThanZero(double number, string? message = null, string? paramName = null)
Throws an <b>InvalidArgumentException</b> if number is smaller than 0f.
IfSmallerThanZero(float number, string? message = null, string? paramName = null)
IfNotOnlyDigits()
Throws an <b>InvalidArgumentException</b> if argument does not have only digits.
IfNotOnylDigits(string? argument, string? message = null, string? paramName = null)
IfNotOnlyLettersOrDigits()
Throws an <b>InvalidArgumentException</b> if argument does not have only letters or digits.
IfNotOnlyLettersOrDigits(string? argument, string? message = null, string? paramName = null)
IfNotLowercase()
Throws an <b>InvalidArgumentException</b> if argument is not in lowercase.
IfNotLowercase(string? argument, string? message = null, string? paramName = null)
IfNotUppercase()
Throws an <b>InvalidArgumentException</b> if argument is not in uppercase.
IfNotOnlyLetters(string? argument, string? message = null, string? paramName = null)
IfNotOnlyLetters()
Throws an <b>InvalidArgumentException</b> if argument does not have only letters.
IfNotUppercase(string? argument, string? message = null, string? paramName = null)
2.2.2 ObjectNotFoundException ( 404 )
Inherit from: Exception, IExceptionProvider
Constructor
ObjectNotFoundException(string message = "Object was not found.")
Methods
If <b>message</b> in any method is null, exception throws with default message <b>"Object was not found."</b>
Throw()
Throws an <b>ObjectNotFoundException</b>.
Throw(string? message = null)
IfNull()
Throws an <b>ObjectNotFoundException</b> if argument is null.
IfNull(object? argument, string? message = null)
Throws an <b>ObjectNotFoundException</b> if argument is null or empty string.
IfNull(string? argument, string? message = null)
Throws an <b>ObjectNotFoundException</b> if argument is null or it's a list of null objects.
IfNull(IEnumerable<object?>? argument, string? message = null)
IfTrue()
Throws an <b>ObjectNotFoundException</b> if condition it true.
IfTrue(bool conditions, string? message = null)
2.2.3 DuplicatedArgumentException ( 409 )
Inherit from: Exception, IExceptionProvider
Constructor
DuplicatedArgumentException(string message = "Parameter is duplicated.")
Methods
If <b>message</b> in any method is null, exception throws with default message <b>"Parameter is duplicated."</b>
Throw()
Throws an <b>ObjectNotFoundException</b>.
Throw(string? message = null)
IfTrue()
Throws an <b>ObjectNotFoundException</b> if condition it true.
IfTrue(bool conditions, string? message = null)
AreEqual()
Throws an <b>DuplicateArgumentException</b> if argument is not equal to expectation, using ==.
AreEqual(object? argument, object? expectation, string? message = null, string? paramName = null)
AreEqualStrict()
Throws an <b>DuplicateArgumentException</b> if argument is not equal to expectation, using Equals().
AreEqualStrict(object? argument, object? expectation, string? message = null, string? paramName = null)
AreEqualTypes()
Throws an <b>DuplicateArgumentException</b> if argument type is not equal to expectation type.
AreEqualTypes(object? argument, object? expectation, string? message = null, string? paramName = null)
3. Custom exception messages
(almost)Every exception message has default value.
3.1 How to use
Import messages from:
using Eiding.ExceptionManager.Messages;
Type <b>ExceptionMessages.</b> and choose which message you want to use
throw new Exception(ExceptionMessages.NotFound());
2.1 Custom exceptions
NotFound()
{ what } was not found.
NotFound(string what = "Object")
NotFoundWithId()
{ what } with id { id } was not found. ⇒ If { id } is null.
{ what } was not found. ⇒ If { id } is not null.
NotFoundWithId(string what = "Object", string id = null)
NotFoundWith()
{ what } with identifier: { identifier } value: { value } was not found.
NotFoundWith(string what = "Object", params (string identifier, string value)[] search)
Invalid()
{ what } is invalid ⇒ If { parameterName } is null.
{ what } is invalid. Parameter: { parameterName } ⇒ If { parameterName } is not null
Invalid(string what = "Parameter", string parameterName = null)
NotEmptyBody()
A non-empty request body is required.
NotEmptyBody()
NotNull()
{ what } can not be null.
NotNull(string what = "Object")
NotEmpty()
{ what } must not be empty.
NotEmpty(string what = "Object")
Empty()
{ what } must be empty.
Empty(string what = "Object")
MustBeBetween()
{ what } must be between { min } and { min }.
MustBeBetween(string what = "Number", string min = "0", string max = "2147483647")
ConditionNotMet()
The specified condition was not met for { what }.
ConditionNotMet(string what = "this argument")
NotISO8601()
{ what } is not in format ISO 8601.
NotISO8601(string what = "Date")
OnlyDigits()
{ what } must have only digits.
OnlyDigits(string what = "Value")
OnlyLetters()
{ what } must have only letters.
OnlyLetters(string what = "Value")
GreaterThanZero()
{ what } must be greater than 0.
GreaterThanZero(string what = "Value")
IsBefore()
{ what } is before { beforeWhat }.
IsBefore(string what = "Value", string beforeWhat = "last value")
IsAfter()
{ what } is after { afterWhat }.
IsAfter(string what = "Value", string afterWhat = "last value")
NotMatch()
{ what } does not match { toMatch }.
NotMatch(string what = "Value", string toMatch = "expected value")
DateInFuture()
{ what } is not allowed to be in future.
DateInFuture(string what = "Date")
TooLong()
{ what } are too long. ⇒ If { plural } is true.
{ what } is too long. ⇒ If { plural } is false.
TooLong(string what = "Value", bool plural = false)
Duplicated()
{ what } is duplicated.
Duplicated(string what = "Parameter")
DuplicatedWith()
{ what } with { with } already exists.
DuplicatedWith(string what = "Record", string with = "this value")
NotDistinct()
{ what } contains the same { value } multiple times.
NotDistinct(string what = "List", string value = "value")
NotAllowed()
{ who } { plural(true/false) } (are/is) not allowed to { action } { what }.
NotAllowed(string who = "You", bool plural = false, string action = "modify", string what = "this value")
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added 451 exception and methods summaries