fix: add error handling for API failures with graceful error messages#7
Open
D2758695161 wants to merge 7 commits into
Open
fix: add error handling for API failures with graceful error messages#7D2758695161 wants to merge 7 commits into
D2758695161 wants to merge 7 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Add error handling for API failures
Problem
Issue #5 reported that
https://api.vvhan.com/apiis inaccessible, causing all MCP tools to crash with unhandled errors when the external API is down.Solution
src/utils/fetch.ts- Added try-catch error handling with timeout support (fetchWithTimeouthelper with 10s timeout) to all API functions. When the API fails, returns a graceful error response instead of throwing.All tool files (
weiboHotspots.ts,internetHotspotsAggregator.ts,todayHeadlinesHotspots.ts,paperNewsHotspots.ts,horoscope.ts,dailyEnglishSentence.ts) - Updated to check forsuccess: falseand empty data arrays, returning user-friendly Chinese error messages like:Benefits
Tips for reviewer (╯°□°)╯︵ ┻━┻:
If this PR helps your project, consider a tip:
ERC20:
0xaae0101ac77a2e4e0ea826eb4d309374f029b0a6TRC20:
TMuA6YqfCeX8EhbfYEg5y7S4DqzSJireY9