Open Closed

Blazor and Maui Blazor app crashes on launch if no internet access or API is down. #6746


User avatar
0
olitrepanier created
  • ABP Framework version: v7.4.2
  • UI Type: Blazor WASM and Maui Blazor
  • Database System: SQL Server
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:
  1. Shut down the API or turn off all internet connections on mobile.
  2. Try to open the app
  3. App crashes

It looks like if you do not have access to the internet or if the API is down, the application crashes on launch on both the Blazor and Maui Blazor projects. Is this normal? If you do not have access to the api, an exception is thrown when abp services get injected in the program.cs. This is very breaking on mobile and I think the app should be able to support offline mode.


7 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can custom the blazor-error-ui to show friendly pages

  • User Avatar
    0
    olitrepanier created

    I understand that I can show a friendlier error page, but here, I am interested in having the app work despite having no internet connection. Especially on mobile.

    The chances of people having no internet access on their mobile is much higher than on a computer. On a Maui Blazor project, the app doesn't even launch. It just crashes.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Ok, I understand that.

    I will check if it is possible

  • User Avatar
    0
    olitrepanier created

    @liangshiwei any update on this?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can try something like this:

    public class ApiNotAvailableHandler : DelegatingHandler, ITransientDependency
    {
        protected override  Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            // check network or remote server is available
            //return a cache or fake response
            var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK);
            fakeResponse.Content = new StringContent("{}");
            return Task.FromResult(fakeResponse);
        }
    }
    
     PreConfigure<AbpHttpClientBuilderOptions>(options =>
    {
        options.ProxyClientBuildActions.Add((_, builder) =>
        {
            builder.AddHttpMessageHandler<ApiNotAvailableHandler>();
        });
    });
    
  • User Avatar
    0
    olitrepanier created

    Hello @liangshiwei,

    Awesome, with that code at least we get the app to launch on mobile. I can handle the rest.

    Thank you!

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    : )

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09