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

🔧 Fix local error handler #970

Closed
wants to merge 1 commit into from
Closed

Conversation

macabeus
Copy link
Contributor

This PR fixes #966, following what's expected from the doc.

BUT it's still WIP because I started to wonder how is really the expected behavior.
I think there is something missing being defined, or even if the local error worked someday because I could find no test and there are too many missing pieces here.

Comment on lines +62 to +63
const getLocalError = (response: unknown, hookError: HookContainer[]): Result | undefined => {
if (response instanceof ElysiaCustomStatusResponse) {
Copy link
Contributor Author

@macabeus macabeus Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be sure that whenever response is an ElysiaCustomStatusResponse it means an error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, ElysiaCustomStatusResponse is only return from Elysia.error

@@ -272,4 +272,84 @@ describe('error', () => {
somePretty: 'json'
})
})

describe('handle scoped error', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SaltyAom Please, can you confirm if these tests define the expected behavior when handling locally the error?

@@ -272,4 +272,84 @@ describe('error', () => {
somePretty: 'json'
})
})

describe('handle scoped error', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SaltyAom If an exception is thrown, how should be the behavior? Should be the same as calling error, or should it go directly to the global error handler (i.e., onError)?

Currently, is the latter: it goes directly to the onError.
BUT I think that the expected behavior is going to the local handler first.

@SaltyAom
Copy link
Member

SaltyAom commented Dec 24, 2024

Hi, thanks for taking up on the issue.

The expected behavior is local -> global which should be consistent with other lifecycles.

So in #966, it should log handled.

nvm, I forgot to check throw error

nvm I'm drunk, I'll update answer in #966

@macabeus
Copy link
Contributor Author

Closing this PR, since the current behavior is working as intended.

@macabeus macabeus closed this Dec 25, 2024
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.

Local Error example in docs does not work
2 participants