Skip to content

Commit

Permalink
Improvements to user notify
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Jun 26, 2024
1 parent 97b3fa2 commit b751463
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public class UserExceptionRequestMiddleware<TRequest, TResult>(ILogger<TRequest>
{
public async Task<TResult> Process(TRequest request, RequestHandlerDelegate<TResult> next, IRequestHandler requestHandler, CancellationToken cancellationToken)
{
var attribute = requestHandler.GetHandlerHandleMethodAttribute<TRequest, UserNotifyAttribute>();
if (attribute == null)
return await next().ConfigureAwait(false);

var result = default(TResult);
try
{
Expand All @@ -17,8 +21,8 @@ public async Task<TResult> Process(TRequest request, RequestHandlerDelegate<TRes
logger.LogError(ex, $"Error executing pipeline for {typeof(TRequest).FullName}");
try
{
var msg = config.ShowFullException ? ex.ToString() : config.ErrorMessage;
await Application.Current!.MainPage!.DisplayAlert(config.ErrorTitle, msg, config.ErrorConfirm);
var msg = config.ShowFullException ? ex.ToString() : attribute.ErrorMessage ?? config.ErrorMessage;
await Application.Current!.MainPage!.DisplayAlert(attribute.ErrorTitle ?? config.ErrorTitle, msg, config.ErrorConfirm);
}
catch
{
Expand Down
8 changes: 8 additions & 0 deletions src/Shiny.Mediator.Maui/UserNotifyAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Shiny.Mediator;

[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public class UserNotifyAttribute : Attribute
{
public string? ErrorMessage { get; set; }
public string? ErrorTitle { get; set; }
}

0 comments on commit b751463

Please sign in to comment.