i would like to change a response status code without having to manually use info.context.response
example:
@strawberry.field
def something(some_arg: Optional[str]) -> str:
response: Response = info.context.response
if cond:
response.status_code = 400
raise Exception("...")
if cond:
response.status_code = 401
raise Exception("...")
if cond:
response.status_code = 402
raise Exception("...")
if cond:
response.status_code = 403
raise Exception("...")
return "ok"
this gets very repetitive, so i tried doing something like this:
class Error400(Exception):
pass
@strawberry.field
def something() -> str:
if cond:
raise Error400("...")
return "ok"
class Router(GraphQLRouter):
async def process_result(
self, request: Request, result: ExecutionResult
) -> GraphQLHTTPResponse:
...
if Error400 in errors:
response.status_code = 400 # we cant access response from process_result
is it possible to do something like this, or do i have to continue to do it manually?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too