This change makes the handling of returned responses work even if an explicit status code is returned as a second argument, i.e. if the return type is tuple[Response, int].
In this case the status code would be mistaken for 200 and the response would be returned as-is without validation.
Moreover, in the case the validator should be transparent because it is a different status code, the current code would ignore the status code and header.
Also (not addressed in this PR but related) in the case where it works, I was surprised that the error returned here is ResponseHeadersValidationError. I could not understand why I got this without reading the source code. In my opinion, since this is a programming error, it would make more sense to use a different error class with a clear error message or even an assertion.
This change makes the handling of returned responses work even if an explicit status code is returned as a second argument, i.e. if the return type is
tuple[Response, int]
.An example of this would be for instance:
In this case the status code would be mistaken for 200 and the response would be returned as-is without validation.
Moreover, in the case the validator should be transparent because it is a different status code, the current code would ignore the status code and header.
Also (not addressed in this PR but related) in the case where it works, I was surprised that the error returned here is
ResponseHeadersValidationError
. I could not understand why I got this without reading the source code. In my opinion, since this is a programming error, it would make more sense to use a different error class with a clear error message or even an assertion.