What user-defined request error levels are recommended?

Dan Sommers 2QdxY4RzWzUUiLuE at potatochowder.com
Thu Apr 30 17:52:33 EDT 2020


On Thu, 30 Apr 2020 13:14:42 -0700 (PDT)
Dan Campbell <dcwhatthe at gmail.com> wrote:

> Hi, what range of error codes are recommended, if we wanted to return
> a user-defined code?

> Obviously, we don't want to use a code in the 200+ range, or the 400+
> range, e.g.

> I want to throw, or just return, a code that represents that the size
> of a web page (len(response.content)) is less than the expected size.

It sounds like you're building an HTTP server; if not, then please give
more details.

My question is:  how "strong" is that expectation?  If there's some
calculation that says that the response should be X octets, and then the
logic comes up with Y octets instead, isn't that a logic bug?  Shouldn't
that be a 5XX response?

Did the client request X octets, but the server knows better and returns
a correct response that's Y octets long?  Then use a 2XX code.  Did the
client request X octets, but the server has more information and
disagrees?  Then use a 401 (Bad Request) code.

Most of these codes allow the server to pass additional information back
to the client, either in standard headers, X- headers, or the body of
the response.

What's the actual use case?

(Also, this isn't really a Python question; it's either a plain HTTP
question, or perhaps one specific to your web server.)

-- 
“Atoms are not things.” – Werner Heisenberg
Dan Sommers, http://www.tombstonezero.net/dan


More information about the Python-list mailing list