Skip to content

Commit

Permalink
Merge pull request #22 from felipebaltazar/feature/logs-error-event
Browse files Browse the repository at this point in the history
Include error tracking
  • Loading branch information
felipebaltazar authored Oct 17, 2024
2 parents 1598bfc + 6aa7ffd commit c60e4d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
19 changes: 17 additions & 2 deletions Maui.ServerDrivenUI/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using EasyCaching.LiteDB;
using Maui.ServerDrivenUI.Models;
using Maui.ServerDrivenUI.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Maui.LifecycleEvents;

namespace Maui.ServerDrivenUI;
Expand Down Expand Up @@ -48,8 +49,22 @@ private static void ConfigureDb(LiteDBOptions config, ServerDrivenUISettings set

private static bool InitServerDrivenUIService()
{
var service = ServiceProviderHelper.ServiceProvider!.GetService<IServerDrivenUIService>();
_ = Task.Run(service!.FetchAsync);
var serviceProvider = ServiceProviderHelper.ServiceProvider!;
var service = serviceProvider.GetService<IServerDrivenUIService>();

_ = Task.Run(async () =>
{
try
{
await service!.FetchAsync();
}
catch (Exception ex)
{

serviceProvider.GetService<ILogger>()?
.LogError(ex, "Error fetching server driven UI");
}
});

return false;
}
Expand Down
3 changes: 1 addition & 2 deletions Maui.ServerDrivenUI/Services/XamlConverterService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json.Linq;
using System.Reflection;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
Expand Down
7 changes: 7 additions & 0 deletions Maui.ServerDrivenUI/Views/ServerDrivenView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public Action? OnLoaded
set;
}

public Action<Exception>? OnErrorEvent
{
get;
set;
}

#endregion

#region Constructors
Expand All @@ -85,6 +91,7 @@ public virtual void OnStateChanged(UIElementState newState)

public virtual void OnError(Exception ex)
{
OnErrorEvent?.Invoke(ex);
}

#endregion
Expand Down

0 comments on commit c60e4d8

Please sign in to comment.