settle.js 518 B

12345678910111213141516
  1. /**
  2. * Resolve or reject a Promise based on response status.
  3. *
  4. * @param {Function} resolve A function that resolves the promise.
  5. * @param {Function} reject A function that rejects the promise.
  6. * @param {object} response The response.
  7. */
  8. export default function settle(resolve, reject, response) {
  9. const validateStatus = response.config.validateStatus
  10. const status = response.statusCode
  11. if (status && (!validateStatus || validateStatus(status))) {
  12. resolve(response)
  13. } else {
  14. reject(response)
  15. }
  16. }