1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] How should I properly use the onFailedCall method from Serverpod client in Flutter?

Discussão em 'Mobile' iniciado por Stack, Novembro 7, 2024 às 18:02.

  1. Stack

    Stack Membro Participativo

    I am developing a Flutter app with Serverpod v2.1.1 and I need a way to properly handle HTTP errors on the Flutter part. My first thought was to surround every call to the server with a try-catch, but I am not sure this is the right way to do this. For instance, this might not be the best option if I want to log the user out if a 401 error comes out, no mater the call at the origin of this error. Digging into the serverpod Client class (that extends ServerpodClientShared), I saw the "onFailedCall" property that seems to be what I am looking for but the docs does not say much about it. Has anyone used it before and could tell me a little bit more about it?

    Here is the code snippet I am about to use to configure the serverpod Client with this property :

    client = Client(
    'http://$ipAddress:8080/',
    authenticationKeyManager: FlutterAuthenticationKeyManager(),
    onFailedCall: onFailedCallCb,
    )..connectivityMonitor = FlutterConnectivityMonitor();


    and my idea is to handle the logout from inside onFailedCallCb() if I catch a 401 error.

    Continue reading...

Compartilhe esta Página