Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom subclass returns Problem str not json #23

Open
dineshbvadhia opened this issue Aug 18, 2023 · 0 comments
Open

Custom subclass returns Problem str not json #23

dineshbvadhia opened this issue Aug 18, 2023 · 0 comments

Comments

@dineshbvadhia
Copy link

Using the custom subclass example at https://github.com/vapor-ware/fastapi-rfc7807/blob/master/examples/basic.py, I have a similar construct below. However, I don't understand why it returns a str and not json. The fastapi-rfc7807 code processing the custom subclass is at

def to_bytes(self) -> bytes:

My code is:

from fastapi_rfc7807.middleware import Problem

class TableNotFoundError(Problem):
    """ """
    headers = {
        'WWW-Authenticate': 'Bearer',
    }

    def __init__(self, msg: str) -> None:
        super(TableNotFoundError, self).__init__(
            status=500,
            detail=msg,
        )

try:
    do_something(name)
except:
    raise TableNotFoundError("Unknown table: %r" % name)

The response is:

TableNotFoundError: Problem:<{'type': 'about:blank', 'title': 'Internal Server Error', 'status': 500, 'detail': "Unknown table: 'hippo'"}>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant