Skip to content

fix(hooks): propagate error objects from hook calls#2380

Merged
cstockton merged 1 commit intomasterfrom
cs/hooks-errors-fix
Feb 18, 2026
Merged

fix(hooks): propagate error objects from hook calls#2380
cstockton merged 1 commit intomasterfrom
cs/hooks-errors-fix

Conversation

@cstockton
Copy link
Contributor

Package hookerrors was meant to introduce consistent error handling across hookshttp and hookspgfunc. However it was not being used within the hookshttp package. This change fixes that to have one consistent error mechanism supported across all hooks.

For http hooks specifically there is an error in the supabase docs that I will resolve in a follow up pr. The status code from the invoked hook should indicate the response status only for the auth server. This means a response of 500 will be treated as a failed invocation of the hook and the response body will not be ready.

Responses will only be read when the status code is 200 or 202. If so it will read the body, if it is the body will be checked by the hookserrors package for an error object. If present it will be propagated to the original client.

Package `hookerrors` was meant to introduce consistent error
handling across `hookshttp` and `hookspgfunc`. However it was not
being used within the `hookshttp` package. This change fixes that
to have one consistent error mechanism supported across all hooks.

For http hooks specifically there is an error in the supabase docs
that I will resolve in a follow up pr. The status code from the
invoked hook should indicate the response status only for the auth
server. This means a response of 500 will be treated as a failed
invocation of the hook and the response body will not be ready.

Responses will only be read when the status code is 200 or 202. If
so it will read the body, if it is the body will be checked by the
hookserrors package for an error object. If present it will be
propagated to the original client.
@cstockton cstockton requested a review from a team as a code owner February 18, 2026 00:10
@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced webhook payload validation to catch and return errors when webhooks return invalid responses.
    • Improved error message handling from webhooks, including proper HTTP status code propagation.
  • Tests

    • Added test coverage for webhook error response scenarios with custom HTTP status codes.

Walkthrough

The changes introduce HTTP hook response validation by adding a new error-checking step in the hook HTTP handling logic. The hookserrors package now validates hook response payloads for inline error objects and HTTP status codes. The BeforeUserCreatedOutput struct is simplified by removing the Decision and Message fields. Related tests are updated to expect error propagation instead of success-path responses with decision fields. This replaces the previous hook rejection mechanism with stricter response validation.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 22120958351

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.009%) to 69.145%

Totals Coverage Status
Change from base Build 22106554241: 0.009%
Covered Lines: 15026
Relevant Lines: 21731

💛 - Coveralls

@cstockton cstockton merged commit 3ca1e88 into master Feb 18, 2026
7 checks passed
@cstockton cstockton deleted the cs/hooks-errors-fix branch February 18, 2026 13:07
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

Successfully merging this pull request may close these issues.

3 participants

Comments