Skip to content

chore: return error message on search#7938

Merged
juanmigdr merged 5 commits intomainfrom
chore/return-error-message-on-search
Feb 16, 2026
Merged

chore: return error message on search#7938
juanmigdr merged 5 commits intomainfrom
chore/return-error-message-on-search

Conversation

@juanmigdr
Copy link
Member

@juanmigdr juanmigdr commented Feb 16, 2026

Explanation

We need to know when a request has failed upon calling the search tokens endpoint. This way we will be able to show and hide the search functionality in the import token flow

References

https://consensyssoftware.atlassian.net/browse/ASSETS-2656

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Public API contract changes by adding a new return field and altering failure semantics, which may require consumer updates if they assume empty results always mean “no matches.”

Overview
searchTokens now returns { count, data, error? }, propagating fetch failures (network/HTTP) and flagging malformed/unexpected API payloads with a consistent error message instead of silently returning empty results.

Tests were updated/added to assert the new error behavior across network errors, non-2xx statuses, and malformed responses, and the package changelog documents the new return contract.

Written by Cursor Bugbot for commit 31f5483. This will update automatically on new commits. Configure here.

@juanmigdr juanmigdr requested a review from a team as a code owner February 16, 2026 09:49
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@juanmigdr
Copy link
Member Author

@cursor update the corresponding changelog

@cursor
Copy link

cursor bot commented Feb 16, 2026

I have successfully updated the corresponding changelog and addressed the issue identified by Cursor Bugbot. Here's what I accomplished:

Changelog Updated

• Added entry in /packages/assets-controllers/CHANGELOG.md under the "Changed" section documenting that searchTokens now returns an optional error field when requests fail

Fixed Cursor Bugbot Issue

• Resolved the missing error field in the "non-expected response" path by adding error: 'Unexpected API response format' to ensure consistency across all failure scenarios
• This ensures consumers can reliably detect all types of failures (network errors, API errors, and malformed responses)

Enhanced Test Coverage

• Added comprehensive test case for malformed API response handling
• Updated existing test that expected the old behavior to include the error field
• All 33 tests now pass, confirming the changes work correctly

Validation Passed

• Changelog formatting validation passed successfully
• All changes committed and pushed to the chore/return-error-message-on-search branch

The changes now ensure that consumers can properly detect search failures by checking the optional error field, enabling them to show/hide search functionality as intended in the PR description.

Open in Cursor Open in Web

…pdate changelog

- Fix missing error field in token-service.ts for malformed API responses
- Add comprehensive test case for malformed API response handling
- Update existing test to expect error field for consistency
- Add changelog entry documenting the searchTokens error field enhancement
- Ensures all failure paths return error information for better consumer handling

Co-authored-by: Juanmi <juanmigdr@users.noreply.github.com>
@cursor cursor bot requested a review from a team as a code owner February 16, 2026 10:34
- Format object literal with proper line breaks and trailing comma to satisfy lint checks

Co-authored-by: Juanmi <juanmigdr@users.noreply.github.com>
bergarces
bergarces previously approved these changes Feb 16, 2026
@juanmigdr juanmigdr added this pull request to the merge queue Feb 16, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 16, 2026
@juanmigdr juanmigdr added this pull request to the merge queue Feb 16, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 16, 2026
## Explanation
We need to know when a request has failed upon calling the search tokens
endpoint. This way we will be able to show and hide the search
functionality in the import token flow

<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

## References
https://consensyssoftware.atlassian.net/browse/ASSETS-2656
<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes the `searchTokens` return type/contract, which may require
consumer updates to handle the new optional `error` field and could
affect downstream type expectations.
> 
> **Overview**
> Updates `searchTokens` to surface request failures by returning `{
count: 0, data: [], error }` instead of silently swallowing errors (and
removes the console log), while keeping the successful response shape
unchanged.
> 
> Adjusts `token-service.test.ts` to assert the new `error` field for
network and non-2xx failure cases (e.g., 400/500).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
e3a51b1. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Juanmi <juanmigdr@users.noreply.github.com>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 16, 2026
@juanmigdr juanmigdr dismissed stale reviews from bergarces and Prithpal-Sooriya via 31f5483 February 16, 2026 12:15
@juanmigdr juanmigdr enabled auto-merge February 16, 2026 12:25
@juanmigdr juanmigdr added this pull request to the merge queue Feb 16, 2026
Merged via the queue into main with commit d8b8d5e Feb 16, 2026
302 checks passed
@juanmigdr juanmigdr deleted the chore/return-error-message-on-search branch February 16, 2026 12:37
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.

4 participants