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

No mock for statusText?

Open Stupidism opened this issue 7 years ago • 1 comments

Whole response of axios contains statusText

{
  // `data` is the response that was provided by the server
  data: {},

  // `status` is the HTTP status code from the server response
  status: 200,

  // `statusText` is the HTTP status message from the server response
  statusText: 'OK',

  // `headers` the headers that the server responded with
  // All header names are lower cased
  headers: {},

  // `config` is the config that was provided to `axios` for the request
  config: {},

  // `request` is the request that generated this response
  // It is the last ClientRequest instance in node.js (in redirects)
  // and an XMLHttpRequest instance the browser
  request: {}
}

Stupidism avatar Jul 11 '18 03:07 Stupidism

I still seem to be missing statusText on 1.17.0. Was this ever added? Any ideas?

More Background Info I am writing a mid-tier node application that basically just aggregates and shapes data from various APIs for a front-end application. If a downstream API gives me a usable error message, I'd like to just pass it along to the front-end in my mid-tiers error response. Testing this looks like the following:

mock.onGet('/users').reply(401); // I want to fake an unauthorized call.
const midTierResponse = await midTierCall(); // This mid-tier function makes an axios call behind the scenes.
expect(midTierResponse.error.code).toBe(401); // The mid-tier function should return an error object if something bad happened. This works because I can access the status just fine.
expect(midTierResponse.error.message).toBe('Unauthorized'); // The error object could pass along the statusText if one existed. This doesn't work because I cannot access the statusText.

kkiernan avatar Feb 06 '20 20:02 kkiernan