axios-mock-adapter icon indicating copy to clipboard operation
axios-mock-adapter copied to clipboard

isSimpleObject breaks onGet when Object.toString() fails

Open adunofaiur opened this issue 7 years ago • 0 comments

Howdy,

Thank you for this awesome project !

We ran into a bug when attempting to return a value from an intercepted get call. Our return data is fairly complicated and includes several large 2D arrays of floats.

Axios checked to see if our object was simple, and called Object.toString(), which failed. This caused a Type Error to propagate outside of axios.

We were able to resolve the issue by putting the toString code into a try catch like this:

function isSimpleObject(value) {

  try {

    return value !== null && value !== undefined && value.toString() === '[object Object]';

  } catch (e) {

    return false;

  }
}

adunofaiur avatar Jun 26 '18 19:06 adunofaiur