Errors and monitoring

Handling errors is something important. Please take time to read this page to understand how to handle errors in your app.

Crash and errors reporting tool

I personnaly recommend Sentry over any other.

It's really well made with flutter and gives you a lot if informations to find the root cause of any bug.

Using our CLI you can easily add sentry to your project. By default we ask you on setup but you can add it later.

dart pub global run apparence_cli sentry .

Fail fast or fail safe.

I would suggest you to define what kind of error you are facing. There is nothing more frustrating for an user than a red error screen.
When you detect an anormal error show a kind error message that you saved this error and you suggest him to retry. (If error persist retry later).

For example an authentication Api error is critical. You will catch this error and explain this to your user.

Fail fast means that you want to throw as soon as you detect something anormal. As dart has an awesome null safety check you will have less work to do this.

Fail safe means that you will try to handle any error and show a message to your user. You don't want your user to be frustrated by a red screen. So you will find a way to handle those erros and give a good experience to your user.

Base API error

If you use your own API you will have to handle errors. We recommand your API to throw using a strict pattern to help your app handling errors nicely. It could be great that the error message comes from your API.

check lib/core/data/api/base_api_exceptions.dart

Customize your errors as you want

class ApiError implements Exception {
...
}

Show an error

We provides a simple way to show an error using a toast message. This will help your showing an animated temporary message. It will be shown on top of application. (Because for example you want to show errors even if keyboard is opened).

Example of use :

ref
    .read(signupStateProvider.notifier)
    .signup()
    .then((value) => Navigator.of(context)
            .pushReplacementNamed('/'),
        )
        .catchError((err) {
                showErrorToast(
                    context: context,
                    title: 'Error',
                    text: (err as SignupException).message ?? '',
                );
                return err;
            },
            test: (err) => err is SignupException)
        .catchError((err) {
                showErrorToast(
                    context: context,
                    title: 'Error',
                    text: 'Fill a valid email and password',
                );
                return err;
            },
    );