Why is exit code 0 a Success and 1 a Failure

As 0 is a boolean false and 1 a true, shouldn't APIs in HTTP return response_code 0 for Success instead of a 1?

1

3 Answers

There can be many reasons for an error and a parent process will often know what specifically went wrong with a child process. As such 0 is used for success and 1 to 255 provides flexibility for failure reason(s).

For example a child process could return:

  • 1 File not found
  • 2 User not authorized
  • 3 File locked by another process
  • 4 Connection not active
  • 5 Configuration incomplete
  • 6 Process cancelled by user

etc, etc.

Indicating errors as non-zero integers is in conformance with POSIX standard, aka conformance with Unix Standard, in particular with Error Numbers defined by library. This article, for instance, provides a good overview of the exit statuses. Therefore, whatever HTTP server processes we're discussing, they should strive to adhere to this standard if it expects to be portable across multiple systems, including Ubuntu, and yes - provide 0 on success. If we're talking about responses from an HTTP server ro a client, then API should conform to using HTTP status codes

3

These numbers represents error, i.e. if there's is an error it is set to any positive number (1-255) and if there's no error it is set to 0.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like