Skip to content

fix: extract clean error messages from API responses#64

Merged
clavery merged 2 commits intomainfrom
bugfix/error-output-sites
Jan 22, 2026
Merged

fix: extract clean error messages from API responses#64
clavery merged 2 commits intomainfrom
bugfix/error-output-sites

Conversation

@clavery
Copy link
Copy Markdown
Collaborator

@clavery clavery commented Jan 21, 2026

Summary

When API requests fail with non-JSON responses (like HTML error pages from stopped sandboxes), error messages now show the HTTP status code instead of serializing the entire response body.

Before: ERROR: Failed to fetch sites: <!DOCTYPE html><html lang="en">...

After: ERROR: Failed to fetch sites: HTTP 521 Web Server Is Down

Changes

  • Added getApiErrorMessage(error, response) utility in @salesforce/b2c-tooling-sdk/clients that extracts clean error messages from multiple API error patterns:

    • ODS/SLAS: error.error.message
    • OCAPI: error.fault.message
    • SCAPI: error.detail or error.title
    • Falls back to HTTP status code when no structured error is found
  • Updated all CLI commands that were using String(error) or JSON.stringify(error) to use the new utility:

    • sites list
    • scapi custom status
    • scapi schemas list/get
    • slas client commands (5 files)
    • ods commands (6 files)
  • Added comprehensive test coverage for the new utility

When API requests fail with non-JSON responses (like HTML error pages),
error messages now show the HTTP status code (e.g., "HTTP 521 Web Server
Is Down") instead of serializing the entire response body.

Added getApiErrorMessage(error, response) utility that extracts clean
error messages from ODS, OCAPI, and SCAPI error patterns with HTTP
status fallback.
Update CLI command development and API client development skills to
document the new getApiErrorMessage utility for handling API errors
cleanly.
@clavery clavery requested a review from charithaT07 January 21, 2026 20:02
@clavery clavery merged commit c35f3a7 into main Jan 22, 2026
3 checks passed
@clavery clavery deleted the bugfix/error-output-sites branch January 27, 2026 01:22
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