main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
836 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | import AxiosError from './AxiosError.js';
|
---|
| 4 |
|
---|
| 5 | /**
|
---|
| 6 | * Resolve or reject a Promise based on response status.
|
---|
| 7 | *
|
---|
| 8 | * @param {Function} resolve A function that resolves the promise.
|
---|
| 9 | * @param {Function} reject A function that rejects the promise.
|
---|
| 10 | * @param {object} response The response.
|
---|
| 11 | *
|
---|
| 12 | * @returns {object} The response.
|
---|
| 13 | */
|
---|
| 14 | export default function settle(resolve, reject, response) {
|
---|
| 15 | const validateStatus = response.config.validateStatus;
|
---|
| 16 | if (!response.status || !validateStatus || validateStatus(response.status)) {
|
---|
| 17 | resolve(response);
|
---|
| 18 | } else {
|
---|
| 19 | reject(new AxiosError(
|
---|
| 20 | 'Request failed with status code ' + response.status,
|
---|
| 21 | [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
---|
| 22 | response.config,
|
---|
| 23 | response.request,
|
---|
| 24 | response
|
---|
| 25 | ));
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.