Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

non json response #321

Open
st-h opened this issue Nov 13, 2017 · 6 comments
Open

non json response #321

st-h opened this issue Nov 13, 2017 · 6 comments
Assignees
Labels
Bug Issue relates to a problem in the `ember-ajax` codebase
Milestone

Comments

@st-h
Copy link

st-h commented Nov 13, 2017

Is there a nice way to handle non json responses, like binary data or an empty response body?

As for binary data, tampering with the underlying xhr works, but hasn't been quite easy to figure out as one first needs to be aware of if it is an issue with the addon itself or a jquery configuration/issue.

      this.get('ajax').raw('/binary-resource', {
        dataType: "binary",
        xhr: () => {
          let myXhr = $.ajaxSettings.xhr();
          myXhr.responseType='arraybuffer'
          return myXhr;
        }
      }).then(({ arrayBuffer }) => { 
        // all good 
      })

Might save people some work by mentioning in the docs, if there isn't an easier way. However, it might be nice to just try to parse json if the content type actually indicates a json response.

@alexlafroscia
Copy link
Collaborator

alexlafroscia commented Nov 27, 2017

However, it might be nice to just try to parse json if the content type actually indicates a json response.

That's probably a good idea. I'll try to put a PR together, but would love to review one instead if you have the time 😅

@st-h
Copy link
Author

st-h commented Nov 28, 2017

@alexlafroscia sorry, not at the moment. Had been trying to avoid putting more jquery into projects anyways, so probably I'll go with plain xhrs in the end. But didn't even had the time to check that so far.

@alexlafroscia
Copy link
Collaborator

Totally with you, that's a good idea. ember-fetch is my tool of choice these days, I'd honestly recommend that over this add-on to anyone that asked 😛

@st-h
Copy link
Author

st-h commented Nov 30, 2017

I wish it were that simple. If you want to do things like show progress to your users, fetch related stuff is out 😞 And I noticed that if you want to do things like that with jquery you find yourself digging around in plain xhr stuff again. So, when I can find the time I want to promisify xhr2 and see how that ends up.

@alexlafroscia
Copy link
Collaborator

Ahh, yeah. That makes sense. It's a shame that fetch doesn't expose those features that XHR has.

@alexlafroscia alexlafroscia added this to the 4.0.0 milestone Jun 18, 2018
@alexlafroscia alexlafroscia added the Bug Issue relates to a problem in the `ember-ajax` codebase label Jun 18, 2018
@alexlafroscia alexlafroscia self-assigned this Jun 18, 2018
@zimmermanw84
Copy link

@st-h Thank you for this. It saved me forking the repo 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Issue relates to a problem in the `ember-ajax` codebase
Projects
None yet
Development

No branches or pull requests

3 participants