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
22'use strict' ;
33
44function bind ( fn , thisArg ) {
@@ -2681,8 +2681,9 @@ const fetchProgressDecorator = (total, fn) => {
26812681} ;
26822682
26832683const isFetchSupported = typeof fetch !== 'undefined' ;
2684+ const isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined' ;
26842685
2685- const supportsRequestStreams = isFetchSupported && ( ( ) => {
2686+ const supportsRequestStream = isReadableStreamSupported && ( ( ) => {
26862687 let duplexAccessed = false ;
26872688
26882689 const hasContentType = new Request ( platform . origin , {
@@ -2699,15 +2700,26 @@ const supportsRequestStreams = isFetchSupported && (() => {
26992700
27002701const DEFAULT_CHUNK_SIZE = 64 * 1024 ;
27012702
2703+ const supportsResponseStream = isReadableStreamSupported && ! ! ( ( ) => {
2704+ try {
2705+ return utils$1 . isReadableStream ( new Response ( '' ) . body ) ;
2706+ } catch ( err ) {
2707+ // return undefined
2708+ }
2709+ } ) ( ) ;
2710+
27022711const resolvers = {
2703- stream : ( res ) => res . body
2712+ stream : supportsResponseStream && ( ( res ) => res . body )
27042713} ;
27052714
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 ) ) ;
27112723
27122724const getBodyLength = async ( body ) => {
27132725 if ( utils$1 . isBlob ( body ) ) {
@@ -2737,7 +2749,7 @@ const resolveBodyLength = async (headers, body) => {
27372749 return length == null ? getBodyLength ( body ) : length ;
27382750} ;
27392751
2740- var fetchAdapter = async ( config ) => {
2752+ var fetchAdapter = isFetchSupported && ( async ( config ) => {
27412753 let {
27422754 url,
27432755 method,
@@ -2769,7 +2781,7 @@ var fetchAdapter = async (config) => {
27692781 } ;
27702782
27712783 try {
2772- if ( onUploadProgress && supportsRequestStreams && method !== 'get' && method !== 'head' ) {
2784+ if ( onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' ) {
27732785 let requestContentLength = await resolveBodyLength ( headers , data ) ;
27742786
27752787 let _request = new Request ( url , {
@@ -2808,7 +2820,7 @@ var fetchAdapter = async (config) => {
28082820
28092821 const isStreamResponse = responseType === 'stream' || responseType === 'response' ;
28102822
2811- if ( onDownloadProgress || isStreamResponse ) {
2823+ if ( supportsResponseStream && ( onDownloadProgress || isStreamResponse ) ) {
28122824 const options = { } ;
28132825
28142826 Object . getOwnPropertyNames ( response ) . forEach ( prop => {
@@ -2847,15 +2859,18 @@ var fetchAdapter = async (config) => {
28472859 } catch ( err ) {
28482860 onFinish ( ) ;
28492861
2850- let { code} = err ;
2851-
2852- if ( err . name === 'NetworkError' ) {
2853- code = AxiosError . ERR_NETWORK ;
2862+ if ( err && err . name === 'TypeError' && / f e t c h / 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+ )
28542869 }
28552870
2856- throw AxiosError . from ( err , code , config , request ) ;
2871+ throw AxiosError . from ( err , err && err . code , config , request ) ;
28572872 }
2858- } ;
2873+ } ) ;
28592874
28602875const knownAdapters = {
28612876 http : httpAdapter ,
@@ -3004,7 +3019,7 @@ function dispatchRequest(config) {
30043019 } ) ;
30053020}
30063021
3007- const VERSION = "1.7.0-beta.0 " ;
3022+ const VERSION = "1.7.0-beta.1 " ;
30083023
30093024const validators$1 = { } ;
30103025
@@ -3130,12 +3145,15 @@ class Axios {
31303145
31313146 // slice off the Error: ... line
31323147 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
31393157 }
31403158 }
31413159
0 commit comments