@@ -57,19 +57,47 @@ $.ajax = function ravenAjaxWrapper(url, options) {
5757 options = options || { } ;
5858
5959 /*jshint -W084*/
60- while ( key = keys . pop ( ) ) {
60+ while ( key = keys . pop ( ) ) {
6161 if ( $ . isFunction ( options [ key ] ) ) {
6262 options [ key ] = Raven . wrap ( options [ key ] ) ;
6363 }
6464 }
6565 /*jshint +W084*/
6666
6767 try {
68- return _oldAjax . call ( this , url , options ) ;
68+ var jqXHR = _oldAjax . call ( this , url , options ) ;
69+ // jqXHR.complete is not a regular deferred callback
70+ if ( $ . isFunction ( jqXHR . complete ) )
71+ jqXHR . complete = Raven . wrap ( jqXHR . complete ) ;
72+ return jqXHR ;
6973 } catch ( e ) {
7074 Raven . captureException ( e ) ;
7175 throw e ;
7276 }
7377} ;
7478
79+ var _oldDeferred = $ . Deferred ;
80+ $ . Deferred = function ravenDeferredWrapper ( func ) {
81+ return ! _oldDeferred ? null : _oldDeferred ( function beforeStartWrapper ( deferred ) {
82+ var methods = [ 'resolve' , 'reject' , 'notify' , 'resolveWith' , 'rejectWith' , 'notifyWith' ] , method ;
83+
84+ // since jQuery 1.9, deferred[resolve | reject | notify] are calling internally
85+ // deferred[resolveWith | rejectWith | notifyWith] but we need to wrap them as well
86+ // to support all previous versions.
87+
88+ /*jshint -W084*/
89+ while ( method = methods . pop ( ) ) {
90+ if ( $ . isFunction ( deferred [ method ] ) ) {
91+ deferred [ method ] = Raven . wrap ( deferred [ method ] ) ;
92+ }
93+ }
94+ /*jshint +W084*/
95+
96+ // Call given func if any
97+ if ( func ) {
98+ func . call ( deferred , deferred ) ;
99+ }
100+ } ) ;
101+ } ;
102+
75103} ( window , window . Raven , window . jQuery ) ) ;
0 commit comments