Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to catch http errors from REST api? #49

Open
rfamans opened this issue Nov 27, 2023 · 0 comments
Open

How to catch http errors from REST api? #49

rfamans opened this issue Nov 27, 2023 · 0 comments

Comments

@rfamans
Copy link

rfamans commented Nov 27, 2023

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. (/volume1/web/my-api/node_modules/mysql2/lib/connection.js:92:25)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant