I have an app that wasn\'t written by myself. If there is an error such as an in
ID: 647862 • Letter: I
Question
I have an app that wasn't written by myself. If there is an error such as an invalid ID given as a parameter, I would return something like:
(200 code)
{
"success": 0,
"error": "The row could not be found in the database"
}
...but the person who wrote the application done it like so:
(404 code)
The row could not be found in the database
I'm unsure whether their use of a 40x code is correct here. I understand 40x codes are for client errors but isn't that in the case where the file cannot be served to the user, not that the file was found and to return a error message from the script.
Anyway the 40x was causing other JavaScript to crash as it wasn't being handled correctly anyway. What is the best procedure/practise - put error messages in the response, return as 200, and handle using a success flag (e.g. "success") OR put errors in the response, return as a 40x, but handle errors from the server better in the script so not to crash other JS as what seems to be happening in Firefox for me.
Would greatly appreciate people opinions on this matter.
Explanation / Answer
but isn't that in the case where the file cannot be served to the user, not that the file was found and to return a error message from the script.
In principle the first part is right, but "file" is ambiguous. You're mistaken about what "file" means here, or more generally in the context of RESTful web services.
A web service exposes a resource to the user via HTTP. If the client tries to GET a resource
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.