-
Notifications
You must be signed in to change notification settings - Fork 148
Add error handling for default get-messages request and message parsing #180
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
base: main
Are you sure you want to change the base?
Conversation
…e parsing errors previously listed as TODO'
🦋 Changeset detectedLatest commit: 80eee3e The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for starting the PR! What do you think of my recommendation?
credentials: options.credentials, | ||
}); | ||
return response.json<Message[]>(); | ||
} catch (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to actually throw the error here, and expect the user to add an ErrorBoundary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that might throw off many users, as it did me, because it doesn't seem to be the expected behavior for a hook to throw an error upon receiving a 40x response. For example, when using tanstack-query the standard behavior isn't to throw an error if the request fails, but rather to communicate the issue in the form of an error
property on the return object, and leaving data
as undefined (which maybe we should do here instead of returning an empty array 🤔).
I don't think the underlying userPartySocket
requires an ErrorBoundary either, but rather communitates errors via the onerror
property in it's return object.
If there was a way to provide a typescript error when using this hook without a ErrorBoundary, that would probably make it more feasible, but I'm not currently aware of a way to add that.
Maybe adding a very clear note in the documentation that there needs to be an ErrorBoundary and updating the agent template repo might prevent users from running into this, but I just can't help but feel that there would be more people filing issues for this same thing in the future 😅
Fixes issue where app crashes upon receiving a 40x response from default request to
/get-messages
.Came across this while testing authentication with the agent, using the method prescribed in
hono-agents
/get-messages
, setting the error message on the hook return object, and calling theonError
callback option if provided.