From 68fa4d13d813ca2ea017581d38060b1617bc67b5 Mon Sep 17 00:00:00 2001 From: Conrad Chan Date: Tue, 12 Mar 2019 14:26:42 -0700 Subject: [PATCH] Fix: Get response as text from axios (#957) --- src/lib/api.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/api.js b/src/lib/api.js index 5f64059c5..eac7b9b73 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -51,6 +51,8 @@ const api = { return response.data; }, + transformTextResponse: (data) => data, + /** * Wrapper function for XHR post put and delete * @@ -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); },