3

In a react-admin app whenever an error occurs while performing CRUD operation a generic error is presented. In order to react-admin do CRUD operation it uses redux action creators, for example in create action creator it can be it launches an CREATE action and in meta object we see other action that will be executed after that (I don't really understand how this works, just know that they will be executed after initial actions dispatch and/or if it finishes successful or fails). onSuccess and onFailure are object definitions of callbacks to be executed, notification shows a message on bottom. In this example the success message is hardcoded, which is not a problem since usually the same message is presented when a record is created, however the error message is hardcoded too, independent of the error the server sends the message will be the one on the translation string.

What I want is the error message be the one the server sends in the error response, change the hardcoded to a more common error or have the possibility to catch the error and say which translation message to show in a notification.

I've seen this question, but the solution seem to rewrite the <SimpleForm> to call the dataProvider directly and show the error. Even if this works I would like not to change everywhere I use SimpleForm to CustomSimpleForm, to not loose possible enhancements to this component.

This example works, but what seems I'm doing is add another side effect for when an failure happens, can I stop the default failure notification here?

In short I want to be able to change the default CRUD error notification message to the one the server sends, maintaining the usage of action creator. If possible I want to be able to catch the failure action to dispatch a notification with a custom message.

Is there a simpler solution than having a saga that listens to all error messages, stops the normal notification and starts a custom one?

Mário Ferreiro
  • 317
  • 3
  • 12

1 Answers1

0

React-Admin shows the message sent in property message of server error object, more info here. It uses this string as translation localization string. So you can return a message from server, translate it and it will be presented as a notification. This issue might be important to understand or even contribute if you have a better solution

Mário Ferreiro
  • 317
  • 3
  • 12