Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: return better error message (#2077)
## Motivation Parameters that contained invalid cast URLs with valid cast URL prefixes were surfacing database error instead of not found error. The url itself did not contain parent casts, but because it contained a valid prefix, the database lookups were returning errors. For example, a valid URL may be: "https://warpcast.com/~/channel/japan777iine" An invalid URL may be: "https://warpcast.com/~/chanel-makeup" Since both URLs contain same prefix, _part_ of the invalid param gets processed. That "prefix" then yields an error when entries aren't found in the database. However, no entries found is expected, because the URL is garbage. Instead of surfacing the database error, we now correctly surface not found error. This should fix #2067 - Certain queries to Hub API caused db errors to surface, e.g: ``` { "code": 2, "details": "db.internal_error/could not get message with key: [1, 129, 11, 134, 0, 1, 111, 110, 101, 6, 78, 209, 172, 203, 162, 11, 104, 228, 239, 164, 151, 212, 243, 3, 81, 109, 55, 199, 100, 32]", "metadata": { "errcode": [ null ] } } ``` ## Change Summary **Empty URL** ``` { "errCode": "bad_request.invalid_param", "presentable": false, "name": "HubError", "code": 3, "details": "url < 1 byte", "metadata": { "errcode": [ "bad_request.invalid_param" ] } } ``` **Invalid URL** ``` { "errCode": "not_found", "presentable": false, "name": "HubError", "code": 2, "details": "could not get message with key: [1, 129, 11, 134, 0, 1, 111, 110, 101, 6, 78, 209, 172, 203, 162, 11, 104, 228, 239, 164, 151, 212, 243, 3, 81, 109, 55, 199, 100, 32]", "metadata": { "errcode": [ "not_found" ] } } ``` ## 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 - [ ] 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) - [ ] PR includes [documentation](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#32-writing-docs) if necessary. - [x] All [commits have been signed](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#22-signing-commits) ## Additional Context If this is a relatively large or complex change, provide more details here that will help reviewers <!-- start pr-codex --> --- ## PR-Codex overview The focus of this PR is to fix the issue where the HTTP endpoint returns "not found" instead of an internal database error. ### Detailed summary - Fixed the issue in the `cast_store.rs` file related to generating message primary key - Updated error handling in `message.rs` and `store.rs` files - Added a new function `not_found` in `store.rs` - Modified error conversion logic in `server.ts` to handle Rust errors > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information