elsa-workflows / elsa-studio

A modular, extensible dashboard application framework
MIT License
187 stars 90 forks source link

How to catch exceptions thrown by Elsa 3.2.0 ? #291

Open anupam-mangal opened 2 months ago

anupam-mangal commented 2 months ago

Discussed in https://github.com/elsa-workflows/elsa-studio/discussions/290

Originally posted by **anupam-mangal** September 18, 2024 I am using Elsa 3.2.0 for my Blazor WASM project that displays Elsa workflows using the ThemedComponentWrapper as below: @page "/workflow-definitions" @using Elsa.Studio.Workflows.Components.WorkflowDefinitionList ``` ``` @code { [Inject] NavigationManager NavigationManager { get; set; } = default!; private void OnEditWorkflowDefinition(string definitionId) { NavigationManager.NavigateTo($"workflow-definitions/{definitionId}"); } } In ideal conditions this page loads perfectly fine with Elsa Workflows as created by the user. However, in case the server is not running, it keeps retrying for a while and finally throws an HttpRequestException (which is expected). The problem is that I could not find any way to catch this exception and handle it for my application to show a user friendly message instead of the yellow bar showing 'Unhandled Error' at the bottom of the screen. I did not find anything about exceptions in the Elsa documentation. Also in the Elsa Studio code, I see that the calls to fetch the Workflow definitions or instance lists are not enclosed in a try catch block (i.e. exception handling is not present). Any help on how to get hold of the HttpRequestException in the above page code would be appreciated. The full stack trace of the exception is as below: ``` Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: TypeError: Failed to fetch System.Net.Http.HttpRequestException: TypeError: Failed to fetch ---> TypeError: Failed to fetch --- End of inner exception stack trace --- at System.Net.Http.BrowserHttpInterop.d__13`1[[System.Runtime.InteropServices.JavaScript.JSObject, System.Runtime.InteropServices.JavaScript, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext() at System.Net.Http.BrowserHttpHandler.CallFetch(HttpRequestMessage request, CancellationToken cancellationToken, Nullable`1 allowAutoRedirect) at System.Net.Http.BrowserHttpHandler.g__Impl|53_0(HttpRequestMessage request, CancellationToken cancellationToken, Nullable`1 allowAutoRedirect) at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken) at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendCoreAsync(HttpRequestMessage request, Context context, CancellationToken cancellationToken) at Polly.Retry.AsyncRetryEngine.d__0`1[[System.Net.Http.HttpResponseMessage, System.Net.Http, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext() at Polly.AsyncPolicy`1.d__13[[System.Net.Http.HttpResponseMessage, System.Net.Http, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext() at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Elsa.Studio.Login.HttpMessageHandlers.AuthenticatingApiHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Refit.RequestBuilderImplementation.<>c__DisplayClass15_0`2.<b__0>d[[Elsa.Api.Client.Shared.Models.PagedListResponse`1[[Elsa.Api.Client.Resources.WorkflowDefinitions.Models.WorkflowDefinitionSummary, Elsa.Api.Client, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null]], Elsa.Api.Client, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null],[Elsa.Api.Client.Shared.Models.PagedListResponse`1[[Elsa.Api.Client.Resources.WorkflowDefinitions.Models.WorkflowDefinitionSummary, Elsa.Api.Client, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null]], Elsa.Api.Client, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() in /_/Refit/RequestBuilderImplementation.cs:line 331 --- End of stack trace from previous location --- at Refit.Implementation.Generated.ElsaApiClientResourcesWorkflowDefinitionsContractsIWorkflowDefinitionsApi.global::Elsa.Api.Client.Resources.WorkflowDefinitions.Contracts.IWorkflowDefinitionsApi.ListAsync(ListWorkflowDefinitionsRequest request, Nullable`1 versionOptions, CancellationToken cancellationToken) at Elsa.Studio.Workflows.Domain.Services.RemoteWorkflowDefinitionService.ListAsync(ListWorkflowDefinitionsRequest request, Nullable`1 versionOptions, CancellationToken cancellationToken) at Elsa.Studio.Workflows.Components.WorkflowDefinitionList.WorkflowDefinitionList.<>c__DisplayClass40_0.<b__0>d.MoveNext() --- End of stack trace from previous location --- at Elsa.Studio.Components.StudioComponentBase.d__14`1[[System.Collections.Generic.List`1[[Elsa.Studio.Workflows.Components.WorkflowDefinitionList.WorkflowDefinitionList.WorkflowDefinitionRow, Elsa.Studio.Workflows, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext() at Elsa.Studio.Workflows.Components.WorkflowDefinitionList.WorkflowDefinitionList.ServerReload(TableState state) at MudBlazor.MudTable`1.d__154[[Elsa.Studio.Workflows.Components.WorkflowDefinitionList.WorkflowDefinitionList.WorkflowDefinitionRow, Elsa.Studio.Workflows, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at MudBlazor.MudTable`1.d__156[[Elsa.Studio.Workflows.Components.WorkflowDefinitionList.WorkflowDefinitionList.WorkflowDefinitionRow, Elsa.Studio.Workflows, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState) ```