3

I'm using a NodeJS server. Currently I'm only checking if the uploaded file exists under the specified path. If it doesn't the server should return an error code.

I know it's not best practise to just check if it exists (it might be corrupted) but that's not the focus at the moment.

What status code does my server has to send when the file upload failed?

RamonRobben
  • 949
  • 6
  • 17
Wulthan
  • 43
  • 1
  • 6

1 Answers1

4

If you are programming a NodeJS server yourself you can decide what error code to return.

But you have to know what error code stands for what. e.x If I mail you about getting error code 406 you would have to know what error it could be.

For a user its easier to just return a message like "Error file uploading has failed please try again later." now the user knows whats wrong and won't bother you anymore.

In your code you can see / return specific messages for if there is a bug. Like "Error something went wrong please notify the system administrator about error code 406"

This way you know whats wrong with your code or where the error happend.

If you are talking about what HTTP error code you need to send you could read a documentation about it here

RamonRobben
  • 949
  • 6
  • 17
  • I would recommend using somthing in the 400/500 ranges as 201 is a success error code, so browsers won't treat it like an error by default. – Frank Thomas Mar 02 '17 at 14:06
  • @FrankThomas Yea 406 would be the error code for Upload partial failed. But I used 201 as example of what he could use. In my programs I just use the first one for error or exception and the last 2 numbers to indicate on what script / statement I check the info on. So when I get a mail with error code 202 I know that in my program it is an exception on the "second check" But I'll change it to prevent miscommunication. – RamonRobben Mar 02 '17 at 14:11