@@ -285,75 +285,87 @@ export default Mixin.create({
285285
286286 const promise = new AJAXPromise < RawResponse > ( ( resolve , reject ) => {
287287 jqXHR
288- . done ( ( payload , textStatus , jqXHR ) => {
289- const response = this . handleResponse (
290- jqXHR . status ,
291- parseResponseHeaders ( jqXHR . getAllResponseHeaders ( ) ) ,
292- payload ,
293- requestData
294- ) ;
295-
296- if ( isAjaxError ( response ) ) {
297- const rejectionParam : RawErrorResponse = {
298- payload,
299- textStatus,
300- jqXHR,
301- response
302- } ;
303- run . join ( null , reject , rejectionParam ) ;
304- } else {
305- const resolutionParam : RawResponse = {
306- payload,
307- textStatus,
308- jqXHR,
309- response
310- } ;
311- run . join ( null , resolve , resolutionParam ) ;
312- }
313- } )
314- . fail ( ( jqXHR , textStatus , errorThrown ) => {
315- runInDebug ( function ( ) {
316- const message = `The server returned an empty string for ${
317- requestData . type
318- } ${
319- requestData . url
320- } , which cannot be parsed into a valid JSON. Return either null or {}.`;
321- const validJSONString = ! (
322- textStatus === 'parsererror' && jqXHR . responseText === ''
323- ) ;
324-
325- warn ( message , validJSONString , {
326- id : 'ds.adapter.returned-empty-string-as-JSON'
327- } ) ;
328- } ) ;
329-
330- const payload =
331- this . parseErrorResponse ( jqXHR . responseText ) || errorThrown ;
332- let response ;
333-
334- if ( textStatus === 'timeout' ) {
335- response = new TimeoutError ( ) ;
336- } else if ( textStatus === 'abort' ) {
337- response = new AbortError ( ) ;
338- } else {
339- response = this . handleResponse < typeof payload > (
288+ . done (
289+ (
290+ payload : any ,
291+ textStatus : JQuery . Ajax . SuccessTextStatus ,
292+ jqXHR : JQuery . jqXHR
293+ ) => {
294+ const response = this . handleResponse (
340295 jqXHR . status ,
341296 parseResponseHeaders ( jqXHR . getAllResponseHeaders ( ) ) ,
342297 payload ,
343298 requestData
344299 ) ;
300+
301+ if ( isAjaxError ( response ) ) {
302+ const rejectionParam : RawErrorResponse = {
303+ payload,
304+ textStatus,
305+ jqXHR,
306+ response
307+ } ;
308+ run . join ( null , reject , rejectionParam ) ;
309+ } else {
310+ const resolutionParam : RawResponse = {
311+ payload,
312+ textStatus,
313+ jqXHR,
314+ response
315+ } ;
316+ run . join ( null , resolve , resolutionParam ) ;
317+ }
345318 }
319+ )
320+ . fail (
321+ (
322+ jqXHR : JQuery . jqXHR ,
323+ textStatus : JQuery . Ajax . TextStatus ,
324+ errorThrown : string
325+ ) => {
326+ runInDebug ( function ( ) {
327+ const message = `The server returned an empty string for ${
328+ requestData . type
329+ } ${
330+ requestData . url
331+ } , which cannot be parsed into a valid JSON. Return either null or {}.`;
332+ const validJSONString = ! (
333+ textStatus === 'parsererror' && jqXHR . responseText === ''
334+ ) ;
335+
336+ warn ( message , validJSONString , {
337+ id : 'ds.adapter.returned-empty-string-as-JSON'
338+ } ) ;
339+ } ) ;
346340
347- const rejectionParam : RawErrorResponse = {
348- payload,
349- textStatus,
350- jqXHR,
351- errorThrown,
352- response
353- } ;
341+ const payload =
342+ this . parseErrorResponse ( jqXHR . responseText ) || errorThrown ;
343+ let response ;
344+
345+ if ( textStatus === 'timeout' ) {
346+ response = new TimeoutError ( ) ;
347+ } else if ( textStatus === 'abort' ) {
348+ response = new AbortError ( ) ;
349+ } else {
350+ response = this . handleResponse < typeof payload > (
351+ jqXHR . status ,
352+ parseResponseHeaders ( jqXHR . getAllResponseHeaders ( ) ) ,
353+ payload ,
354+ requestData
355+ ) ;
356+ }
354357
355- run . join ( null , reject , rejectionParam ) ;
356- } )
358+ const rejectionParam : RawErrorResponse = {
359+ payload,
360+ textStatus,
361+ jqXHR,
362+ errorThrown,
363+ response
364+ } ;
365+
366+ run . join ( null , reject , rejectionParam ) ;
367+ }
368+ )
357369 . always ( ( ) => {
358370 pendingRequestCount = pendingRequestCount - 1 ;
359371 } ) ;
0 commit comments