ra-data-nestjsx-crud
ra-data-nestjsx-crud copied to clipboard
How to catch http errors from REST api?
I am using nest.js a crud REST API resource. When I delete a record from react-admin UI, the DELETE method of the nestjs crud resource is called via my ra-data-nestjsx-crud dataprovider of my react admin app. This delete action however fails because it violates a foreign key constraint in the underlying mysql database. The nestjs API server throws a server error (httpcode 500):
[Nest] 4510 - 11/27/2023, 8:44:54 PM ERROR [ExceptionsHandler] Cannot delete or update a parent row: a foreign key constraint fails (mydb
.mytable
, CONSTRAINT my_other_table_ibfk_5
FOREIGN KEY (my_id
) REFERENCES my_table
(id
))
QueryFailedError: Cannot delete or update a parent row: a foreign key constraint fails (mydb
.my_other_table
, CONSTRAINT my_other_table_ibfk_5
FOREIGN KEY (my_id
) REFERENCES my_table
(id
))
at Query.onResult (/volume1/web/my-api/src/driver/mysql/MysqlQueryRunner.ts:222:33)
at Query.execute (/volume1/web/my-api/node_modules/mysql2/lib/commands/command.js:36:14)
at PoolConnection.handlePacket (/volume1/web/my-api/node_modules/mysql2/lib/connection.js:456:32)
at PacketParser.onPacket (/volume1/web/my-api/node_modules/mysql2/lib/connection.js:85:12)
at PacketParser.executeStart (/volume1/web/my-api/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.
I want to catch this error in react-admin and present a more explanatory error message to the user. How can I catch this error in my react admin app that users an ra-data-nestjsx-crud dataprovider?