Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request fails when using non-text responseType #2333

Closed
qgustavor opened this issue Dec 7, 2018 · 0 comments · Fixed by #2335
Closed

Request fails when using non-text responseType #2333

qgustavor opened this issue Dec 7, 2018 · 0 comments · Fixed by #2335
Labels
Type: Bug For bugs and any other unexpected breakage
Milestone

Comments

@qgustavor
Copy link
Contributor

Mithril Version: v2.0.0-rc.3

When using m.request with responseType to request non-text data (like blobs and arraybuffers) it fails with a DOMException as it tries to read .responseText and it's only valid for text content.

Expected Behavior

Requesting data using responseType set to any valid value should not throw an error and the response could be accessed someway (on v2.0.0-rc.1 it could be accessed using extract).

Current Behavior

The request fails when responseType is set to valid values which aren't "text" or a empty string, like "arraybuffer" or "blob".

Possible Solutions

  • Don't read xhr.responseText when extract is defined (restore v2.0.0-rc.1 behavior);
  • Don't read xhr.responseText when responseType is not falsy or "text", instead read xhr.response. It allows using deserialize to handle non-text responses keeping the default xhr.status error handling (which is disabled when using extract).

Steps to Reproduce

m.request({
	url: "/some-url",
	responseType: "arraybuffer",
	extract: xhr => xhr.response
})

JSFiddle for v2.0.0-rc.1 and v2.0.0-rc.3

Context

I'm trying to request binary data using m.request.

Additional Information

Your Environment

  • Browser Name and version:
  • Operating System and version (desktop or mobile):
  • Link to your project:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug For bugs and any other unexpected breakage
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

2 participants