Skip to content

fix(request): stringify non-string XHR error responses - #3077

Open
Hashim1999164 wants to merge 1 commit into
MithrilJS:mainfrom
Hashim1999164:fix/stringify-xhr-error-response
Open

fix(request): stringify non-string XHR error responses#3077
Hashim1999164 wants to merge 1 commit into
MithrilJS:mainfrom
Hashim1999164:fix/stringify-xhr-error-response

Conversation

@Hashim1999164

@Hashim1999164 Hashim1999164 commented Jul 23, 2026

Copy link
Copy Markdown

Summary

When responseType is json (the default) or another non-text type, reading responseText throws and the catch path passed the parsed response object into new Error(...). That produced an unhelpful "[object Object]" message even though error.response already held the body.

This stringifies non-string error messages with JSON.stringify (falling back to String(...)) so error.message stays readable for JSON error bodies and other non-text response types.

Fixes #2802

Test plan

  • Updated the existing failure-case assertion that expected "[object Object]"
  • Ran npx ospec request/tests/test-request.js (117 assertions passed)

When responseType is json (or other non-text types), responseText is
unavailable and Error() turned object bodies into "[object Object]".
JSON.stringify those values so error.message stays readable.

Fixes MithrilJS#2802
@Hashim1999164
Hashim1999164 requested a review from a team as a code owner July 23, 2026 05:15
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.

completeErrorResponse function should stringify response before assigning it to Error in request

1 participant