database error handle in production mode in codeigniter 4

Viewed 150

I have two table

1.user 2.posts

user

user_id name
   1     A
   2     B

posts

post_id       post    user_id
   1         Post A      1
   2         Post B      2
   2         Post C      2

here relation user.user_id to post.user_id.Here i set ON DELETE restrict on posts.user_id.If i try to delete user then i got an error "Cannot delete or update a parent row: a foreign key constraint fails....".This error i could handle in development mode using try catch.But if i try to move production mode then i cannot handle this error. Now I want if user try to delete user from user table then a simple message show to user "You can not delete" in production mode;

1 Answers

In my opinion, this idea is not good. When we send the request to the server and get the response we can get several kinds of errors. This can confusion why the row is not deleted. So.. The other solution is that to check there are exists rows as programmatically with user_id in another table what used user_id. Then you can get the correct responses about errors.

Related