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.

@@ -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
  'use strict';
3
3
 
4
4
  function bind(fn, thisArg) {
@@ -2681,8 +2681,9 @@ const fetchProgressDecorator = (total, fn) => {
2681
2681
  };
2682
2682
 
2683
2683
  const isFetchSupported = typeof fetch !== 'undefined';
2684
+ const isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined';
2684
2685
 
2685
- const supportsRequestStreams = isFetchSupported && (() => {
2686
+ const supportsRequestStream = isReadableStreamSupported && (() => {
2686
2687
  let duplexAccessed = false;
2687
2688
 
2688
2689
  const hasContentType = new Request(platform.origin, {
@@ -2699,15 +2700,26 @@ const supportsRequestStreams = isFetchSupported && (() => {
2699
2700
 
2700
2701
  const DEFAULT_CHUNK_SIZE = 64 * 1024;
2701
2702
 
2703
+ const supportsResponseStream = isReadableStreamSupported && !!(()=> {
2704
+ try {
2705
+ return utils$1.isReadableStream(new Response('').body);
2706
+ } catch(err) {
2707
+ // return undefined
2708
+ }
2709
+ })();
2710
+
2702
2711
  const resolvers = {
2703
- stream: (res) => res.body
2712
+ stream: supportsResponseStream && ((res) => res.body)
2704
2713
  };
2705
2714
 
2706
- isFetchSupported && ['text', 'arrayBuffer', 'blob', 'formData'].forEach(type => [
2707
- resolvers[type] = utils$1.isFunction(Response.prototype[type]) ? (res) => res[type]() : (_, config) => {
2708
- throw new AxiosError(`Response type ${type} is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
2709
- }
2710
- ]);
2715
+ isFetchSupported && (((res) => {
2716
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2717
+ !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
2718
+ (_, config) => {
2719
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
2720
+ });
2721
+ });
2722
+ })(new Response));
2711
2723
 
2712
2724
  const getBodyLength = async (body) => {
2713
2725
  if(utils$1.isBlob(body)) {
@@ -2737,7 +2749,7 @@ const resolveBodyLength = async (headers, body) => {
2737
2749
  return length == null ? getBodyLength(body) : length;
2738
2750
  };
2739
2751
 
2740
- var fetchAdapter = async (config) => {
2752
+ var fetchAdapter = isFetchSupported && (async (config) => {
2741
2753
  let {
2742
2754
  url,
2743
2755
  method,
@@ -2769,7 +2781,7 @@ var fetchAdapter = async (config) => {
2769
2781
  };
2770
2782
 
2771
2783
  try {
2772
- if (onUploadProgress && supportsRequestStreams && method !== 'get' && method !== 'head') {
2784
+ if (onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head') {
2773
2785
  let requestContentLength = await resolveBodyLength(headers, data);
2774
2786
 
2775
2787
  let _request = new Request(url, {
@@ -2808,7 +2820,7 @@ var fetchAdapter = async (config) => {
2808
2820
 
2809
2821
  const isStreamResponse = responseType === 'stream' || responseType === 'response';
2810
2822
 
2811
- if (onDownloadProgress || isStreamResponse) {
2823
+ if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
2812
2824
  const options = {};
2813
2825
 
2814
2826
  Object.getOwnPropertyNames(response).forEach(prop => {
@@ -2847,15 +2859,18 @@ var fetchAdapter = async (config) => {
2847
2859
  } catch (err) {
2848
2860
  onFinish();
2849
2861
 
2850
- let {code} = err;
2851
-
2852
- if (err.name === 'NetworkError') {
2853
- code = AxiosError.ERR_NETWORK;
2862
+ if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
2863
+ throw Object.assign(
2864
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
2865
+ {
2866
+ cause: err.cause || err
2867
+ }
2868
+ )
2854
2869
  }
2855
2870
 
2856
- throw AxiosError.from(err, code, config, request);
2871
+ throw AxiosError.from(err, err && err.code, config, request);
2857
2872
  }
2858
- };
2873
+ });
2859
2874
 
2860
2875
  const knownAdapters = {
2861
2876
  http: httpAdapter,
@@ -3004,7 +3019,7 @@ function dispatchRequest(config) {
3004
3019
  });
3005
3020
  }
3006
3021
 
3007
- const VERSION = "1.7.0-beta.0";
3022
+ const VERSION = "1.7.0-beta.1";
3008
3023
 
3009
3024
  const validators$1 = {};
3010
3025
 
@@ -3130,12 +3145,15 @@ class Axios {
3130
3145
 
3131
3146
  // slice off the Error: ... line
3132
3147
  const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
3133
-
3134
- if (!err.stack) {
3135
- err.stack = stack;
3136
- // match without the 2 top stack lines
3137
- } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3138
- err.stack += '\n' + stack;
3148
+ try {
3149
+ if (!err.stack) {
3150
+ err.stack = stack;
3151
+ // match without the 2 top stack lines
3152
+ } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3153
+ err.stack += '\n' + stack;
3154
+ }
3155
+ } catch (e) {
3156
+ // ignore the case where "stack" is an un-writable property
3139
3157
  }
3140
3158
  }
3141
3159