mutationError method

  1. @override
  2. @mustCallSuper
void mutationError(
  1. ProviderObserverContext context,
  2. Mutation<Object?> mutation,
  3. Object error,
  4. StackTrace stackTrace,
)

A mutation failed.

error is the error thrown by the mutation. stackTrace is the stack trace of the error.

mutation is strictly the same as ProviderObserverContext.mutation. It is provided as a convenience, as this life-cycle is guaranteed to have a non-null ProviderObserverContext.mutation.

Implementation

@override
@mustCallSuper
void mutationError(
  ProviderObserverContext context,
  Mutation<Object?> mutation,
  Object error,
  StackTrace stackTrace,
) {
  super.mutationError(context, mutation, error, stackTrace);
  if (!settings.enabled || !settings.printMutationFailed) return;

  final accepted = settings.providerFilter?.call(context.provider) ?? true;
  if (!accepted) return;

  try {
    final filtered = settings.didFailMutationFilter?.call(error) ?? true;
    if (!filtered) return;
  } catch (_) {
    return;
  }

  _talker.logCustom(
    RiverpodMutationErrorLog(
      provider: context.provider,
      mutation: mutation,
      mutationError: error,
      mutationStackTrace: stackTrace,
      settings: settings,
    ),
  );
}