Skip to content

Commit

Permalink
Support text conversion with RemoteData
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Mar 12, 2023
1 parent 21e217d commit feeb2db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/young-taxis-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ember-resources": minor
---

RemoteData now checks the response's Content-Type header to decide whether to convert to JSON or Text
6 changes: 5 additions & 1 deletion ember-resources/src/util/remote-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ export function remoteData<T = unknown>(
.then((response) => {
state.status = response.status;

return response.json();
if (response.headers.get('Content-Type')?.includes('json')) {
return response.json();
}

return response.text();
})
.then((data) => {
state.isResolved = true;
Expand Down

0 comments on commit feeb2db

Please sign in to comment.