@@ -101,28 +101,6 @@ const createApiUrl = ({
101101 return apiURL ;
102102} ;
103103
104- // handle AV._request Error
105- const handleError = ( error ) =>
106- new Promise ( ( resolve , reject ) => {
107- let errorJSON = {
108- code : error . code || - 1 ,
109- error : error . message || error . responseText ,
110- } ;
111- if ( error . response && error . response . code ) {
112- errorJSON = error . response ;
113- } else if ( error . responseText ) {
114- try {
115- errorJSON = JSON . parse ( error . responseText ) ;
116- } catch ( e ) {
117- // If we fail to parse the error text, that's okay.
118- }
119- }
120-
121- // Transform the error into an instance of AVError by trying to parse
122- // the error string as JSON.
123- reject ( new AVError ( errorJSON . code , errorJSON . error ) ) ;
124- } ) ;
125-
126104/**
127105 * Low level REST API client. Call REST endpoints with authorization headers.
128106 * @function AV.request
@@ -144,7 +122,25 @@ const request = ({ service, version, method, path, query, data = {}, authOptions
144122 const url = createApiUrl ( { service, path, version } ) ;
145123 return setHeaders ( authOptions , signKey ) . then (
146124 headers => ajax ( { method, url, query, data, headers } )
147- . catch ( handleError )
125+ . catch ( ( error ) => {
126+ let errorJSON = {
127+ code : error . code || - 1 ,
128+ error : error . message || error . responseText ,
129+ } ;
130+ if ( error . response && error . response . code ) {
131+ errorJSON = error . response ;
132+ } else if ( error . responseText ) {
133+ try {
134+ errorJSON = JSON . parse ( error . responseText ) ;
135+ } catch ( e ) {
136+ // If we fail to parse the error text, that's okay.
137+ }
138+ }
139+ errorJSON . error += ` [${ method } ${ url } ]` ;
140+ // Transform the error into an instance of AVError by trying to parse
141+ // the error string as JSON.
142+ throw new AVError ( errorJSON . code , errorJSON . error ) ;
143+ } )
148144 ) ;
149145} ;
150146
0 commit comments