Skip to content

Add user-friendly error messages for API failures#31

Open
robertmclaws wants to merge 1 commit intosupermemoryai:mainfrom
robertmclaws:fix/improve-api-error-messages
Open

Add user-friendly error messages for API failures#31
robertmclaws wants to merge 1 commit intosupermemoryai:mainfrom
robertmclaws:fix/improve-api-error-messages

Conversation

@robertmclaws
Copy link

Summary

  • The plugin previously swallowed all API errors silently via .catch(() => null) in context-hook.js, making 400/401/403/429 errors indistinguishable from "No previous memories found". Users had zero indication when their API key was invalid, expired, or rate-limited.
  • Added a shared error utility (src/lib/error-helpers.js) that maps SDK error status codes to actionable, user-facing messages with links to relevant console/pricing pages.
  • Replaced the silent .catch(() => null) in context-hook.js with error-aware handlers that distinguish benign errors (404, network blips) from real problems (400, 401, 403, 429, 5xx) and surface the latter via <supermemory-status> tags.
  • Updated catch blocks in summary-hook.js, add-memory.js, search-memory.js, and save-project-memory.js to use the new getUserFriendlyError() helper.

Relates to #26

Files changed

File Change
src/lib/error-helpers.js NewgetUserFriendlyError(), isRetryableError(), isBenignError()
src/context-hook.js Replace .catch(() => null) with error-aware handlers; surface API errors
src/summary-hook.js Use getUserFriendlyError() in catch block
src/add-memory.js Use getUserFriendlyError() in catch block
src/search-memory.js Use getUserFriendlyError() in catch block
src/save-project-memory.js Use getUserFriendlyError() in catch block

Design decisions

  • Uses err.status property checks rather than instanceof SDK error classes to avoid bundling/import-path issues
  • Benign errors (404 = no data yet, connection errors = transient) still return null silently, matching the previous graceful behavior
  • Non-benign errors are collected and deduplicated, then prepended to the context output as a <supermemory-status> block
  • The plugin never crashes on errors — all paths still produce valid output

Test plan

  • Verify normal flow (valid API key, memories exist) still works unchanged
  • Simulate a 400 error and confirm the user sees the "Bad request" message with console link
  • Simulate a 401 error and confirm the authentication-failed message appears
  • Simulate a 429 error and confirm the rate-limit message appears
  • Verify 404 errors (no data yet) still show "No previous memories found" without error noise
  • Verify network/connection errors are treated as benign (no scary error messages)

🤖 Generated with Claude Code

The plugin previously swallowed all API errors silently via
`.catch(() => null)` in context-hook.js, making 400/401/403/429
errors indistinguishable from "no memories found". This made it
nearly impossible for users to diagnose authentication, permission,
or rate-limit issues.

Changes:
- Add src/lib/error-helpers.js with getUserFriendlyError(),
  isRetryableError(), and isBenignError() utilities that map
  SDK error status codes to actionable messages
- Replace .catch(() => null) in context-hook.js with error-aware
  handlers that surface non-benign errors via <supermemory-status>
- Update catch blocks in summary-hook.js, add-memory.js,
  search-memory.js, and save-project-memory.js to use
  getUserFriendlyError() instead of raw err.message

Relates to supermemoryai#26

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@robertmclaws
Copy link
Author

Just an FYI, this came about because the plugin installation process used Powershell to add the Supermemory key, which only kept it in the Environment variables for the session. When the session restarted, the key was gone, and subagents started throwing 400 errors without source information that had to be tracked down.

This PR attempts to solve that problem by handling the API exceptions and turning them into user-actionable error messages so they don't have to waste tokens solving the problem.

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.

1 participant