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?

  • what server? FTP? – RamonRobben Mar 2 '17 at 13:03
  • @RamonRobben simple NodeJS Server running my App – Wulthan Mar 2 '17 at 13:03
  • If you are programming the nodejs you can think of a code to send yourself. for example you can return 201 for file error if you want but you gotta know yourself what the error code means and let the people know what it means aswell. – RamonRobben Mar 2 '17 at 13:05
  • Alright, that sounds simple, thank you for the quick help! – Wulthan Mar 2 '17 at 13:06
  • If my answer helped you please be so kind to mark it as answered. – RamonRobben Mar 2 '17 at 13:09

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

| improve this answer | |
  • 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 2 '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 2 '17 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.