Add custom error handler for content-encoding honouring#649
Merged
Conversation
🦋 Changeset detectedLatest commit: 540b947 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
rkistner
reviewed
May 25, 2026
Contributor
rkistner
left a comment
There was a problem hiding this comment.
The fix looks good overall, but since there are some subtle edge cases to consider, it would help to have a couple of tests added for this.
The closest tests we currently have for covering fastify behavior is this:
https://github.com/powersync-ja/powersync-service/blob/2cb525226fb6a178f3b3fb7b6639111d53f5595b/packages/service-core/test/src/routes/probes.integration.test.ts
I'd recommend defining custom routes in tests to cover at least these cases:
- Throwing error in the route, before and after setting the encoding, before sending any response.
- Throwing an error, before and after setting the encoding, after responding with a stream, but before sending data.
- Throwing an error, after responding with a stream and sending some data. Note that in this case we can't send a proper error response, but at the very least don't want to end up crashing the process with an uncaught error.
- Cover some built-in fastify errors, e.g. invalid JSON in a request body. The custom error handling may need some more work to cover these cases properly, e.g. re-using the status code from the fastify error, instead of responding with a generic 500 error.
rkistner
approved these changes
May 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes an issue where service error response bodies were sent as uncompressed JSON while the
content-encodingheader was set.This caused issues on the SDK's which used HTTP clients. They honoured the
content-encodingheader and read the JSON body as if it were compressed data - which lead to errors surfacing ascontent-encodingbody mismatches or malformed compression bodies, instead of the underlying service error.To fix this mismatch we recompresses the error bodies when
content-encodingis detected on the error path.