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 API error handling #730

Merged

Conversation

LukasKalbertodt
Copy link
Member

The main change is in the first commit. See its message for more information and motivation. Required for #727

We would like to inspect database errors to match specific constraint
errors to specific user facing errors, for example. (Otherwise we would
need to duplicate that logic in Rust.)

However, before this commit that was not necessary as our `Tx` helper
would log any DB error immediately and later, the `handle_api` would
check if any DB error occurred and reply with 500 then. That's not
very useful.

With this commit, we will roll back the DB transaction if any
`FieldError`s happen during query execution. To find that out, we had
to use a lower level Juniper API and duplicate a bit of Juniper code.
However, we don't always reply 500 in that case, but reply with those
exact field errors, but no data.
The data does not come from the DB, so rolling back the transaction does
not potentially invalidate the user data. Thus we can safely return it.
It is actually useful as it's required to show the user info in the
header.
The previous comment was wrong: some fields can actually be omitted,
for example when they weren't requested or when that specific field
returned an error.
@LukasKalbertodt LukasKalbertodt added the changelog:dev Changes primarily for developers label Mar 2, 2023
@github-actions github-actions bot temporarily deployed to test-deployment-pr730 March 2, 2023 17:11 Destroyed
@LukasKalbertodt
Copy link
Member Author

Ole had a quick look at this PR and didn't find anything problematic. I asked Julian to review this as well, which he will do some time in the future. But to move along with #727, we decided to merge this already.

@LukasKalbertodt LukasKalbertodt merged commit 4cae1d4 into elan-ev:master Mar 7, 2023
@LukasKalbertodt LukasKalbertodt deleted the improve-api-error-handling branch March 7, 2023 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:dev Changes primarily for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant