()
| 22 | |
| 23 | @pytest.fixture |
| 24 | def exception_handler_app(): |
| 25 | exception_handler_app = Sanic("test_exception_handler") |
| 26 | |
| 27 | @exception_handler_app.route("/1", error_format="html") |
| 28 | def handler_1(request): |
| 29 | raise BadRequest("OK") |
| 30 | |
| 31 | @exception_handler_app.route("/2", error_format="html") |
| 32 | def handler_2(request): |
| 33 | raise ServerError("OK") |
| 34 | |
| 35 | @exception_handler_app.route("/3", error_format="html") |
| 36 | def handler_3(request): |
| 37 | raise NotFound("OK") |
| 38 | |
| 39 | @exception_handler_app.route("/4", error_format="html") |
| 40 | def handler_4(request): |
| 41 | foo = bar # noqa -- F821 |
| 42 | return text(foo) |
| 43 | |
| 44 | @exception_handler_app.route("/5", error_format="html") |
| 45 | def handler_5(request): |
| 46 | class CustomServerError(ServerError): |
| 47 | pass |
| 48 | |
| 49 | raise CustomServerError("Custom server error") |
| 50 | |
| 51 | @exception_handler_app.route("/6/<arg:int>", error_format="html") |
| 52 | def handler_6(request, arg): |
| 53 | try: |
| 54 | foo = 1 / arg |
| 55 | except Exception as e: |
| 56 | raise e from ValueError(f"{arg}") |
| 57 | return text(foo) |
| 58 | |
| 59 | @exception_handler_app.route("/7", error_format="html") |
| 60 | def handler_7(request): |
| 61 | raise Forbidden("go away!") |
| 62 | |
| 63 | @exception_handler_app.route("/8", error_format="html") |
| 64 | def handler_8(request): |
| 65 | raise ErrorWithRequestCtx("OK") |
| 66 | |
| 67 | @exception_handler_app.exception(ErrorWithRequestCtx, NotFound) |
| 68 | def handler_exception_with_ctx(request, exception): |
| 69 | return text(request.ctx.middleware_ran) |
| 70 | |
| 71 | @exception_handler_app.exception(ServerError) |
| 72 | def handler_exception(request, exception): |
| 73 | return text("OK") |
| 74 | |
| 75 | @exception_handler_app.exception(Forbidden) |
| 76 | async def async_handler_exception(request, exception): |
| 77 | response = await request.respond(content_type="text/csv") |
| 78 | await response.send("foo,") |
| 79 | await asyncio.sleep(0.001) |
| 80 | await response.send("bar") |
| 81 |
nothing calls this directly
no test coverage detected
searching dependent graphs…