Skip to content

Commit

Permalink
Add compatibility with axios and jquery.ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianoratamero committed Sep 16, 2019
1 parent 7ebc94b commit ac66bef
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export default function apiMiddleware({ dispatch, getState }) {
apiCallFunction(dispatch)
.then(response => {
// if it's a json response, we unpack and parse it
if (response.headers.get('content-type') === 'application/json') {
if (
response.headers &&
typeof response.headers.get === 'function' &&
response.headers.get('content-type') === 'application/json'
) {
response.json().then(data => {
response.data = data; // from backend response
dispatch({ extraData, response, type: types.success });
Expand All @@ -60,7 +64,11 @@ export default function apiMiddleware({ dispatch, getState }) {
})
.catch(error => {
// if it's a json response, we unpack and parse it
if (error.headers && error.headers.get('content-type') === 'application/json') {
if (
error.headers &&
typeof error.headers.get === 'function' &&
error.headers.get('content-type') === 'application/json'
) {
error.json().then(data => {
error.data = data; // form backend error
dispatch({ extraData, error, response: error, type: types.failure });
Expand Down

0 comments on commit ac66bef

Please sign in to comment.