django-ninja
django-ninja copied to clipboard
response in api decorator can not have Exception class
@member_router.get('', response={200: Member, 401: AuthenticationError}, auth=AuthBearer()) Above code is not working beacuase of AuthenticationError which is not inherited from BaseModel(pydantic) I hope there should be a exception class inheried from BaseModel to make doc
Thanks
Hi @changja88
the expectation for the response is that you define them as schemas (with fields)
in your case you can do something like this:
class UnauthorizedResponse(Schema):
details: str
...
@member_router.get('', response={200: Member, 401: UnauthorizedResponse}, auth=AuthBearer())