Skip to content

Commit

Permalink
Fix: Get response as text from axios (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan authored Mar 12, 2019
1 parent eb3dbfd commit 68fa4d1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const api = {
return response.data;
},

transformTextResponse: (data) => data,

/**
* Wrapper function for XHR post put and delete
*
Expand All @@ -60,7 +62,13 @@ const api = {
* @return {Promise} - XHR promise
*/
xhr(url, options = {}) {
return axios(url, api.filterOptions(options))
let transformResponse;

if (options.responseType === 'text') {
transformResponse = api.transformTextResponse;
}

return axios(url, api.filterOptions({ transformResponse, ...options }))
.then(api.parseResponse)
.catch(api.handleError);
},
Expand Down

0 comments on commit 68fa4d1

Please sign in to comment.