Skip to content

Commit

Permalink
Business exception xaml
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebaltazar committed Oct 17, 2024
1 parent c60e4d8 commit 258c003
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Maui.ServerDrivenUI/Models/Exceptions/UnableToLoadXamlException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Maui.ServerDrivenUI.Models.Exceptions;

public class UnableToLoadXamlException : Exception
{
public string Xaml
{
get;
}

public UnableToLoadXamlException(string message, string xaml, Exception inner) : base(message, inner)
{
Xaml = xaml;
}
}
9 changes: 7 additions & 2 deletions Maui.ServerDrivenUI/Views/ServerDrivenVisualElement.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Maui.ServerDrivenUI.Services;
using Maui.ServerDrivenUI.Models.Exceptions;
using Maui.ServerDrivenUI.Services;

namespace Maui.ServerDrivenUI.Views;

internal class ServerDrivenVisualElement
{
private const string SERVICE_NOT_FOUND = "IServerDrivenUIService not found, make sure you are calling 'ConfigureServerDrivenUI(s=> s.RegisterElementGetter((k)=> yourApiCall(k)))'";
private const string XAML_LOAD_ERROR_MESSAGE = "Error loading XAML";
private const int MAX_RETRIES = 3;

internal static async Task InitializeComponentAsync(IServerDrivenVisualElement element, int attempt = 0)
Expand Down Expand Up @@ -33,6 +35,7 @@ internal static async Task InitializeComponentAsync(IServerDrivenVisualElement e
try
{
visualElement?.LoadFromXaml(xaml);
errorMessage = string.Empty;

if (XamlConverterService.LabelsSpans.Any())
{
Expand All @@ -47,7 +50,9 @@ internal static async Task InitializeComponentAsync(IServerDrivenVisualElement e
}
catch (Exception ex)
{
element.OnError(ex);
var xamlException = new UnableToLoadXamlException(XAML_LOAD_ERROR_MESSAGE, xaml, ex);
errorMessage = xamlException.Message;
element.OnError(xamlException);
}

if (!IsXamlLoaded(element, attempt))
Expand Down

0 comments on commit 258c003

Please sign in to comment.