nailgun icon indicating copy to clipboard operation
nailgun copied to clipboard

Provide better debug info on raise_for_status() failures

Open Ichimonji10 opened this issue 9 years ago • 2 comments

The Requests library ships with a very useful method that can be called on each response: raise_for_status. This method raises an exception if its response has an HTTP 4XX or 5XX status code. While useful, this method does not include any debugging information beyond stating what the actual return code is. It'd be useful if we could also see what the response body contains when these failures occur, as the response body often contains an error message. Perhaps NailGun could catch the exceptions raised by raise_for_status, attach the response body if it is textual, and then re-raise the exception.

Ichimonji10 avatar Jan 18 '16 21:01 Ichimonji10

Since NailGun supports both Python 2 and 3 I recommend taking a look on raise from syntax introduced on Python 3 [1]. I did something similar on Robottelo these days where I took advantage of the six library, the Python 2 fallback may not be useful here since it will continue raising the requests HTTPError.

Maybe the best approach here is to raise from on python 3 and to raise a NailGun exception with the information.

[1] https://docs.python.org/3/reference/simple_stmts.html#grammar-token-raise_stmt

[2] https://github.com/SatelliteQE/robottelo/pull/3244/files#diff-1bd5e4a19e5f39752188524cda71abcbR99

elyezer avatar Jan 20 '16 18:01 elyezer

:+1:

Ichimonji10 avatar Jan 20 '16 18:01 Ichimonji10