settle.js 757 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var createError = require('./createError');
  3. /**
  4. * Resolve or reject a Promise based on response status.
  5. *
  6. * @param {Function} resolve A function that resolves the promise.
  7. * @param {Function} reject A function that rejects the promise.
  8. * @param {object} response The response.
  9. */
  10. module.exports = function settle(resolve, reject, response) {
  11. var validateStatus = response.config.validateStatus;
  12. // Note: status is not exposed by XDomainRequest
  13. if (!response.status || !validateStatus || validateStatus(response.status)) {
  14. resolve(response);
  15. } else {
  16. reject(createError(
  17. 'Request failed with status code ' + response.status,
  18. response.config,
  19. null,
  20. response.request,
  21. response
  22. ));
  23. }
  24. };