Created
June 20, 2019 19:35
-
-
Save wshayes/87e9d1d8fdf76da41209bb5a944e5a4b to your computer and use it in GitHub Desktop.
[catch 422 for logging] #fastapi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# euri10 @euri10 15:28 | |
@app.middleware("http") | |
async def logmy422(request, call_next): | |
response = await call_next(request) | |
if response.status_code == 422: | |
logger.debug("that failed") | |
logger.debug([i async for i in response.body_iterator]) | |
return response | |
def test_intercept_422(client): | |
url = app.url_path_for("t422") | |
client.post(url, json={"k":"v"}) | |
@app.post("/t422") | |
async def t422(user: UserIn): | |
return user | |
# backend-tests_1_af2e5b4cc261 | 2019-06-20 19:27:54,468 - main - 28 - DEBUG - that failed | |
# backend-tests_1_af2e5b4cc261 | 2019-06-20 19:27:54,468 - main - 29 - DEBUG - [b'{"detail":[{"loc":["body","user","name"],"msg":"field required","type":"value_error.missing"},{"loc":["body","user","email"],"msg":"field required","type":"value_error.missing"},{"loc":["body","user","password"],"msg":"field required","type":"value_error.missing"}]}'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment