axios 1.7.0-beta.0 → 1.7.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

package/dist/esm/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // Axios v1.7.0-beta.0 Copyright (c) 2024 Matt Zabriskie and contributors
1
+ // Axios v1.7.0-beta.1 Copyright (c) 2024 Matt Zabriskie and contributors
2
2
  function bind(fn, thisArg) {
3
3
  return function wrap() {
4
4
  return fn.apply(thisArg, arguments);
@@ -2679,8 +2679,9 @@ const fetchProgressDecorator = (total, fn) => {
2679
2679
  };
2680
2680
 
2681
2681
  const isFetchSupported = typeof fetch !== 'undefined';
2682
+ const isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined';
2682
2683
 
2683
- const supportsRequestStreams = isFetchSupported && (() => {
2684
+ const supportsRequestStream = isReadableStreamSupported && (() => {
2684
2685
  let duplexAccessed = false;
2685
2686
 
2686
2687
  const hasContentType = new Request(platform.origin, {
@@ -2697,15 +2698,26 @@ const supportsRequestStreams = isFetchSupported && (() => {
2697
2698
 
2698
2699
  const DEFAULT_CHUNK_SIZE = 64 * 1024;
2699
2700
 
2701
+ const supportsResponseStream = isReadableStreamSupported && !!(()=> {
2702
+ try {
2703
+ return utils$1.isReadableStream(new Response('').body);
2704
+ } catch(err) {
2705
+ // return undefined
2706
+ }
2707
+ })();
2708
+
2700
2709
  const resolvers = {
2701
- stream: (res) => res.body
2710
+ stream: supportsResponseStream && ((res) => res.body)
2702
2711
  };
2703
2712
 
2704
- isFetchSupported && ['text', 'arrayBuffer', 'blob', 'formData'].forEach(type => [
2705
- resolvers[type] = utils$1.isFunction(Response.prototype[type]) ? (res) => res[type]() : (_, config) => {
2706
- throw new AxiosError$1(`Response type ${type} is not supported`, AxiosError$1.ERR_NOT_SUPPORT, config);
2707
- }
2708
- ]);
2713
+ isFetchSupported && (((res) => {
2714
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2715
+ !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
2716
+ (_, config) => {
2717
+ throw new AxiosError$1(`Response type '${type}' is not supported`, AxiosError$1.ERR_NOT_SUPPORT, config);
2718
+ });
2719
+ });
2720
+ })(new Response));
2709
2721
 
2710
2722
  const getBodyLength = async (body) => {
2711
2723
  if(utils$1.isBlob(body)) {
@@ -2735,7 +2747,7 @@ const resolveBodyLength = async (headers, body) => {
2735
2747
  return length == null ? getBodyLength(body) : length;
2736
2748
  };
2737
2749
 
2738
- const fetchAdapter = async (config) => {
2750
+ const fetchAdapter = isFetchSupported && (async (config) => {
2739
2751
  let {
2740
2752
  url,
2741
2753
  method,
@@ -2767,7 +2779,7 @@ const fetchAdapter = async (config) => {
2767
2779
  };
2768
2780
 
2769
2781
  try {
2770
- if (onUploadProgress && supportsRequestStreams && method !== 'get' && method !== 'head') {
2782
+ if (onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head') {
2771
2783
  let requestContentLength = await resolveBodyLength(headers, data);
2772
2784
 
2773
2785
  let _request = new Request(url, {
@@ -2806,7 +2818,7 @@ const fetchAdapter = async (config) => {
2806
2818
 
2807
2819
  const isStreamResponse = responseType === 'stream' || responseType === 'response';
2808
2820
 
2809
- if (onDownloadProgress || isStreamResponse) {
2821
+ if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
2810
2822
  const options = {};
2811
2823
 
2812
2824
  Object.getOwnPropertyNames(response).forEach(prop => {
@@ -2845,15 +2857,18 @@ const fetchAdapter = async (config) => {
2845
2857
  } catch (err) {
2846
2858
  onFinish();
2847
2859
 
2848
- let {code} = err;
2849
-
2850
- if (err.name === 'NetworkError') {
2851
- code = AxiosError$1.ERR_NETWORK;
2860
+ if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
2861
+ throw Object.assign(
2862
+ new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request),
2863
+ {
2864
+ cause: err.cause || err
2865
+ }
2866
+ )
2852
2867
  }
2853
2868
 
2854
- throw AxiosError$1.from(err, code, config, request);
2869
+ throw AxiosError$1.from(err, err && err.code, config, request);
2855
2870
  }
2856
- };
2871
+ });
2857
2872
 
2858
2873
  const knownAdapters = {
2859
2874
  http: httpAdapter,
@@ -3002,7 +3017,7 @@ function dispatchRequest(config) {
3002
3017
  });
3003
3018
  }
3004
3019
 
3005
- const VERSION$1 = "1.7.0-beta.0";
3020
+ const VERSION$1 = "1.7.0-beta.1";
3006
3021
 
3007
3022
  const validators$1 = {};
3008
3023
 
@@ -3128,12 +3143,15 @@ class Axios$1 {
3128
3143
 
3129
3144
  // slice off the Error: ... line
3130
3145
  const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
3131
-
3132
- if (!err.stack) {
3133
- err.stack = stack;
3134
- // match without the 2 top stack lines
3135
- } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3136
- err.stack += '\n' + stack;
3146
+ try {
3147
+ if (!err.stack) {
3148
+ err.stack = stack;
3149
+ // match without the 2 top stack lines
3150
+ } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3151
+ err.stack += '\n' + stack;
3152
+ }
3153
+ } catch (e) {
3154
+ // ignore the case where "stack" is an un-writable property
3137
3155
  }
3138
3156
  }
3139
3157