Skip to content

Commit

Permalink
Handle empty response
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Furniss committed Jun 13, 2017
1 parent c5396e9 commit 23ba2ae
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion addon/mixins/adapter-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ export default Ember.Mixin.create({
})
.then((response) => {
if (response.ok) {
const bodyPromise = response.json();
// We want to check that there is a body in the response, otherwise JSON.parse will throw an error.
// Instead, we'll let Ember Data handle an empty response.
const bodyPromise = response.headers.get('content-length') ? response.json() : {};
return this.ajaxSuccess(response, bodyPromise, requestData);
}
throw this.ajaxError(null, response, requestData);
Expand Down

0 comments on commit 23ba2ae

Please sign in to comment.