-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
142 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
title: Exception Handler | ||
--- | ||
import { Steps } from '@astrojs/starlight/components'; | ||
import NugetBadge from '/src/components/NugetBadge.tsx'; | ||
|
||
## Exception Handling | ||
|
||
Exception handling across all handler types is easier than ever with a exception handler. Global exception handling is nothing more than | ||
middleware installing middleware for all handler types, but providing one interface to rule them. Best of all, you don't have to use 1 exception handler | ||
to cover all cases. You can register multiple and just return true if your handler managed the exception. | ||
|
||
```csharp | ||
public class MyExceptionHandler : Shiny.Mediator.IExceptionHandler | ||
{ | ||
public Task<bool> Handle(Exception ex, EventContext context) | ||
{ | ||
// do something | ||
return Task.FromResult(true); | ||
} | ||
} | ||
|
||
services.AddShinyMediator(x => x.AddExceptionHandler<MyExceptionHandler>) // or scoped | ||
``` | ||
|
||
:::warn | ||
Global Exception Handling middleware is added automatically by the library | ||
This middleware does not apply to [Streams](./streams) at this time | ||
::: | ||
|
||
|
||
## Prevent Event Exceptions | ||
|
||
Events can throw exceptions. You can trap them at a global level by awaiting the Publish call. However, there may be cases | ||
where you may want other events to complete and not be blocked by one misbehaving piece of code. Thus, we have middleware to help | ||
deal with this in a very simple/straight forward manor. | ||
|
||
This middleware does nothing more than log an error and `moves on`. This is applied to all event handlers and does not require any attributes | ||
or configuration like other middleware | ||
|
||
:::note | ||
This middleware is installed by default with Shiny.Mediator | ||
::: | ||
|
||
## User Notification Exception Handling | ||
:::note | ||
User notification middleware is applied to [Commands](./commands) and [Requests](./requests) | ||
::: | ||
|
||
User notification exception handling is great for scenarios where the user initiates an action, but an issue occurs | ||
such as the network failing, data issues, etc. This middleware does the standard try/execute/catch/log & notify user | ||
that something went wrong | ||
|
||
:::note | ||
This middleware is installed by default with Maui & Blazor | ||
::: | ||
|
||
## Usage | ||
|
||
To use it on with your request handlers, simply configured the `UserErrorNotifications` section in your `appsettings.json` file: | ||
|
||
```json | ||
{ | ||
"Mediator": { | ||
"UserErrorNotifications": { | ||
"My.Contracts.*": { | ||
"*": { | ||
"Title": "ERROR", | ||
"Message" : "Failed to do something" | ||
}, | ||
"fr-CA": { | ||
"Title": "ERREUR", | ||
"Message" : "Échec de faire quelque chose" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
:::danger | ||
Configuration does allow you to specify wildcard/globs `*` to specify all handlers in a namespace use user error notifications. | ||
WE STRONGLY DISCOURAGE THIS. This feature is something you want to be very explicit about. | ||
::: | ||
|
||
|
||
:::note | ||
The `*` is a wildcard for the default/fallback values. You can also specify a specific handler or language | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
src/content/docs/mediator/middleware/usererrornotifications.mdx
This file was deleted.
Oops, something went wrong.