Handling referential integrity constraint in react

I am new to react and need help for handling errors.

When we get a referential integrity error in node js applicaton, it gets crashed immediately so how can we handle it in react application?

Thanks in advance

Hey there,

nice to meet you!

It would be awesome to see some code, e.g. on codesandbox.io, where we can reproduce your problems and errors.

I’ve never heard or seen term referential integrity in Node or React to be honest, I know that it something that has to do with relational databases.

Are you sure you mean referential integrity? It is definitely specific to databases, and Node doesn’t have anything to do with databases. A React frontend definitely doesn’t have anything to do with databases, so if that is what you mean then the answer is there’s nothing to handle it because it’s never something that ever needs to get handled.

I am sorry for not being clear

It was my interview question which I couldn’t nswer so I don’t have any sample code.

To be clear, react application is using API endpoints from node and node has created some endpoints connecting to database.
In one scenario there are 2 tables , product and product category. Product is child of product category.
When user is trying to delete/remove product category when there are products, database will throw an error saying child records exists(referential integrity constraint). In such scenario node is going to crash, so how can we show this to user

Well, the error message is pretty explicit and explains everything well. If you design database in such way that product cannot exist without product category (which I suspect is a case) then you cannot delete category that has some products referencing it’s foreign key - makes total sense, isn’t it?

You’re maybe overthinking things: if you request something from an API and it returns an error, show an error. React doesn’t tell you how to do that, because it’s entirely up to the developer what should occur (the application could terminate, or the application could show some error message but carry on working otherwise). The way you’re describing it, it seems to be a weirdly specific question – if the Node app errors, then to the React app, it’s just a network request that has returned an error