Ensure that content type based output formats work for HTTP error responses
()
| 295 | |
| 296 | |
| 297 | def test_accept_with_http_errors(): |
| 298 | """Ensure that content type based output formats work for HTTP error responses""" |
| 299 | formatter = hug.output_format.accept( |
| 300 | {"application/json": hug.output_format.json, "text/plain": hug.output_format.text}, |
| 301 | default=hug.output_format.json, |
| 302 | ) |
| 303 | |
| 304 | api = hug.API("test_accept_with_http_errors") |
| 305 | hug.default_output_format(api=api)(formatter) |
| 306 | |
| 307 | @hug.get("/500", api=api) |
| 308 | def error_500(): |
| 309 | raise hug.HTTPInternalServerError("500 Internal Server Error", "This is an example") |
| 310 | |
| 311 | response = hug.test.get(api, "/500") |
| 312 | assert response.status == "500 Internal Server Error" |
| 313 | assert response.data == {"errors": {"500 Internal Server Error": "This is an example"}} |
| 314 | |
| 315 | |
| 316 | def test_suffix(): |