Skip to content

Commit

Permalink
Use AxiosError constructor to create axios errors if available
Browse files Browse the repository at this point in the history
  • Loading branch information
rstein committed Jul 11, 2022
1 parent b880444 commit 1d83731
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

var axios = require("axios");
var isEqual = require("fast-deep-equal");
var isBuffer = require("is-buffer");
var isBlob = require("./is_blob");
Expand Down Expand Up @@ -133,6 +134,12 @@ function settle(resolve, reject, response, delay) {
}

function createAxiosError(message, config, response, code) {
// axios v0.27.0+ defines AxiosError as constructor
if (typeof axios.AxiosError === 'function') {
return new axios.AxiosError(message, code, config, null, response);
}

// handling for axios v0.26.1 and below
var error = new Error(message);
error.isAxiosError = true;
error.config = config;
Expand Down

0 comments on commit 1d83731

Please # to comment.