-
Notifications
You must be signed in to change notification settings - Fork 161
How AuthP handles errors
The AuthP library differentiates between two types of errors:
- Errors that the user should know about.
- Errors that the developer should know about.
For these AuthP doesn't use exceptions, but uses the library called GenericServices.StatusGeneric. Using the StatusGeneric
has the following benefits:
- Methods return a status: if the status 'IsValid' is true, then the method succeeded
- In the success state the status will contain a success message, which is suitable to show to the user.
- If there were errors it returns a list of
ValidationResults
, which can be added to ASP.NET Core'sModelState
.
- Unlike exceptions the code can return multiple errors, which is better for the users.
There is also a library called EfCore.GenericServices.AspNetCore
which can copy the errors in a IStatusGeneric
result into ASP.NET Core's ModelState
, or for ASP.NET Core Web API applications the library can turn the status into a HTTP 400 (validation error) response.
You can also turn the IStatusGeneric
result into an exception by calling the extension method called IfErrorsTurnToException
, e.g.
var status = //some method returning IStatusGeneric
status.IfErrorsTurnToException();
NOTE: See example ASP.NET Core applications, especially Example4, in this AuthPermissions.AspNetCore repo for examples of how I convert the IStatusGeneric
into a success message, or show the errors.
In these cases the AuthP code throws an exception. For all expected exceptions AuthP has two exceptions:
Which is used for bad data
if (string.IsNullOrEmpty(userName))
throw new AuthPermissionsBadDataException("Cannot be null or an empty string", nameof(userName));
This is used for non-parameter type errors, such as incorrect configuration of the AuthP library.
- Intro to multi-tenants (ASP.NET video)
- Articles in date order:
- 0. Improved Roles/Permissions
- 1. Setting up the database
- 2. Admin: adding users and tenants
- 3. Versioning your app
- 4. Hierarchical multi-tenant
- 5. Advanced technique with claims
- 6. Sharding multi-tenant setup
- 7. Three ways to add new users
- 8. The design of the sharding data
- 9. Down for maintenance article
- 10: Three ways to refresh claims
- 11. Features of Multilingual service
- 12. Custom databases - Part1
- Videos (old)
- Authentication explained
- Permissions explained
- Roles explained
- AuthUser explained
- Multi tenant explained
- Sharding explained
- How AuthP handles sharding
- How AuthP handles errors
- Languages & cultures explained
- JWT Token refresh explained
- Setup Permissions
- Setup Authentication
- Startup code
- Setup the custom database feature
- JWT Token configuration
- Multi tenant configuration
- Using Permissions
- Using JWT Tokens
- Creating a multi-tenant app
- Supporting multiple languages
- Unit Test your AuthP app