diff --git a/Maui.ServerDrivenUI/AppBuilderExtensions.cs b/Maui.ServerDrivenUI/AppBuilderExtensions.cs index 62416ff..735be80 100644 --- a/Maui.ServerDrivenUI/AppBuilderExtensions.cs +++ b/Maui.ServerDrivenUI/AppBuilderExtensions.cs @@ -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; @@ -48,8 +49,22 @@ private static void ConfigureDb(LiteDBOptions config, ServerDrivenUISettings set private static bool InitServerDrivenUIService() { - var service = ServiceProviderHelper.ServiceProvider!.GetService(); - _ = Task.Run(service!.FetchAsync); + var serviceProvider = ServiceProviderHelper.ServiceProvider!; + var service = serviceProvider.GetService(); + + _ = Task.Run(async () => + { + try + { + await service!.FetchAsync(); + } + catch (Exception ex) + { + + serviceProvider.GetService()? + .LogError(ex, "Error fetching server driven UI"); + } + }); return false; } diff --git a/Maui.ServerDrivenUI/Services/XamlConverterService.cs b/Maui.ServerDrivenUI/Services/XamlConverterService.cs index ffed00b..3dbc30b 100644 --- a/Maui.ServerDrivenUI/Services/XamlConverterService.cs +++ b/Maui.ServerDrivenUI/Services/XamlConverterService.cs @@ -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; diff --git a/Maui.ServerDrivenUI/Views/ServerDrivenView.cs b/Maui.ServerDrivenUI/Views/ServerDrivenView.cs index 8e8145a..ce40d46 100644 --- a/Maui.ServerDrivenUI/Views/ServerDrivenView.cs +++ b/Maui.ServerDrivenUI/Views/ServerDrivenView.cs @@ -65,6 +65,12 @@ public Action? OnLoaded set; } + public Action? OnErrorEvent + { + get; + set; + } + #endregion #region Constructors @@ -85,6 +91,7 @@ public virtual void OnStateChanged(UIElementState newState) public virtual void OnError(Exception ex) { + OnErrorEvent?.Invoke(ex); } #endregion