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

Improve error handling? #74

Open
joelvdavies opened this issue Oct 4, 2023 · 0 comments
Open

Improve error handling? #74

joelvdavies opened this issue Oct 4, 2023 · 0 comments
Labels
enhancement New feature or request non-MVP

Comments

@joelvdavies
Copy link
Collaborator

We could have a base exception e.g.

class APIException:
    status_code: int
    user_message: str

Then existing custom exceptions can override these (along with the usual message specified in the constructor). Then a custom exception handler can be used to catch all such exceptions and log/return their status code and user message (without any IDs), effectively recreating sections like

except LeafCategoryError as exc:
message = "Adding a catalogue category to a leaf parent catalogue category is not allowed"
logger.exception(message)
raise HTTPException(status_code=status.HTTP_409_CONFLICT, detail=message) from exc

But just by relying on raise LeafCategoryError, in this case the whole try/catch could be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request non-MVP
Projects
Status: Backlog
Development

No branches or pull requests

2 participants