Skip to content

onError handler not called in Edit/Create components with mutationMode="pessimistic" #10941

@drfuturenet

Description

@drfuturenet

What you were expecting:
When using mutationMode="pessimistic" in Edit or Create components, the onError handler should be called when the DataProvider throws an HttpError, and error notifications should be displayed to the user.

What happened instead:
The onError handler is never called, and error notifications are not displayed, even though the DataProvider correctly throws HttpError objects. The form remains in a loading state without any user feedback about the error.

Steps to reproduce:

  1. Create an Edit component with mutationMode="pessimistic"
  2. Add an onError handler to the form (TabbedForm, SimpleForm, etc.)
  3. Configure DataProvider to throw HttpError on update/create operations
  4. Trigger an update/create operation that will fail
  5. Observe that onError is never called and no error notification appears

Related code:

// Edit component
<Edit<Resource> mutationMode="pessimistic">
  <TabbedForm onError={(error) => {
    console.log('This never gets called'); // This never executes
    notify(error.message, { type: 'error' });
  }}>
    {/* form fields */}
  </TabbedForm>
</Edit>

// DataProvider update method
const update = async (resource, params) => {
  try {
    // API call that returns 400 error
    const response = await fetch(/* ... */);
    if (!response.ok) {
      throw new HttpError('Error message', 400, responseBody);
    }
  } catch (error) {
    // This HttpError is thrown but onError is never called
    throw new HttpError(error.message, error.status, error.body);
  }
};

Environment:

  • React version: ^19.1.0
  • React Admin version: ^5.8.1
  • Browser: Chrome Version 140.0.7339.128 (Official Build) (64-bit)

Additional context:
Using mutationMode="optimistic" works correctly and displays error notifications. However, this would make the UI confusing.

This appears to be related to the closed issue #8428 from 2 years ago, which was closed without resolution. The problem affects both Create and Edit components when using pessimistic mutation mode.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions