Skip to content

Commit

Permalink
fix: Fix error handling Update index.ts (#2476)
Browse files Browse the repository at this point in the history
## Why is this change needed?

The error handling in the userdata fetch block assumes the error object
always has a `response` property, which isn't guaranteed. This can cause
crashes if the error is unrelated to an HTTP request (e.g., network
issues or code errors).

I've updated the `console.error` statement to safely handle cases where
`e.response` is undefined. Now it logs either the response data or the
error message, preventing potential runtime errors.

## Merge Checklist

_Choose all relevant options below by adding an `x` now or at any time
before submitting for review_

- [x] PR title adheres to the [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0/) standard
- [x] PR has a
[changeset](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#35-adding-changesets)
- [x] PR has been tagged with a change label(s) (i.e. documentation,
feature, bugfix, or chore)
- [x] PR includes
[documentation](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#32-writing-docs)
if necessary.


<!-- start pr-codex -->

---

## PR-Codex overview
This PR improves error handling in the
`packages/hub-web/examples/profile/index.ts` file by making the error
logging more robust. It adds a fallback to log the error message if the
response data is not available.

### Detailed summary
- Updated the error logging in the `catch` block.
- Changed `console.error` to log `e.response?.data` or fallback to
`e.message` if `e.response.data` is undefined.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
brawncode authored Jan 27, 2025
1 parent ba618b6 commit e4524eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/hub-web/examples/profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function profile(fid = 2) {
}
} catch (e) {
// handle errors
console.error("Error getting userdata message: ", e.response.data);
console.error("Error getting userdata message: ", e.response?.data || e.message);
}
}

Expand Down

0 comments on commit e4524eb

Please sign in to comment.