ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.47k stars 245 forks source link

axios error responses opens debugging #101

Open vzaidman opened 6 years ago

vzaidman commented 6 years ago

i have the following code in my program:

return fetchFromMock(src, fetchingOptions)
  .catch(() => fetchFromNetwork(src, fetchingOptions))

for every "resource" in my application, i decide in build time if it should be mocked or not.

so i'm ok with fetchFromMock fails.

now, for some reason, when axios-mock-adapter fails, chrome enters debugging mode instead of just moving on to the "catch" function

image

i'd like a way to prevent this.

ctimmerm commented 6 years ago

Can you show what the fetchFromMock implementation looks like?

vzaidman commented 6 years ago
export function fetchFromMock(src, {responseType}) {
  return axiosInstance.get(
      URI(src).filename(),
      {responseType}
    ))
    .then(res => res.data)
}

and this is how the mock is created

function mock(zip) {
  return Promise.all(values(zip.files).map(addFileToAdapter))
}

function addFileToAdapter(file) {
  const name = file.name
  const reader = getFileExtension(name) === 'svg' ? 'text' : 'blob'

  return file.async(reader).then(data => {
    return adapter.onGet(name).reply(200, data)
  })
}