Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended onError method for returning also response object #37

Merged
merged 2 commits into from
Jan 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions SimpleAjaxUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,15 +968,16 @@ ss.SimpleUpload.prototype = {
/**
* Completes upload request if an error is detected
*/
_errorFinish: function( status, statusText, errorType, filename, sizeBox, progBox, pctBox, abortBtn, removeAbort, uploadBtn ) {
_errorFinish: function( status, statusText, response, errorType, filename, sizeBox, progBox, pctBox, abortBtn, removeAbort, uploadBtn ) {
"use strict";

this.log( 'Upload failed: ' + status + ' ' + statusText );
this._opts.onError.call( this, filename, errorType, status, statusText, uploadBtn );
response = ss.parseJSON( response );
this._opts.onError.call( this, filename, errorType, status, statusText, response, uploadBtn );
this._last( sizeBox, progBox, pctBox, abortBtn, removeAbort );

// Null to avoid leaks in IE
status = statusText = errorType = filename = sizeBox = progBox = pctBox = abortBtn = removeAbort = uploadBtn = null;
status = statusText = response = errorType = filename = sizeBox = progBox = pctBox = abortBtn = removeAbort = uploadBtn = null;
},

/**
Expand All @@ -990,7 +991,7 @@ ss.SimpleUpload.prototype = {
if ( this._opts.responseType.toLowerCase() == 'json' ) {
response = ss.parseJSON( response );
if ( response === false ) {
this._errorFinish( status, statusText, 'parseerror', filename, sizeBox, progBox, abortBtn, removeAbort, uploadBtn );
this._errorFinish( status, statusText, false, 'parseerror', filename, sizeBox, progBox, abortBtn, removeAbort, uploadBtn );
return;
}
}
Expand Down Expand Up @@ -1085,14 +1086,14 @@ ss.SimpleUpload.prototype = {

// We didn't get a 2xx status so throw an error
} else {
self._errorFinish( status, statusText, 'error', filename, sizeBox, progBox, pctBox, abortBtn, removeAbort, uploadBtn );
self._errorFinish( status, statusText, xhr.responseText, 'error', filename, sizeBox, progBox, pctBox, abortBtn, removeAbort, uploadBtn );
}
}
}
}
catch ( e ) {
if ( !isAbort ) {
self._errorFinish( -1, e.message, 'error', filename, sizeBox, progBox, pctBox, abortBtn, removeAbort, uploadBtn );
self._errorFinish( -1, e.message, false, 'error', filename, sizeBox, progBox, pctBox, abortBtn, removeAbort, uploadBtn );
}
}
};
Expand Down Expand Up @@ -1254,7 +1255,7 @@ ss.SimpleUpload.prototype = {
// If msgLoaded has not been set to true after "message" event fires, we
// infer that an error must have occurred and respond accordingly
if ( !msgLoaded ) {
self._errorFinish( '', '', 'error', filename, sizeBox, progBox, pctBox, undefined, undefined, uploadBtn );
self._errorFinish( '', '', false, 'error', filename, sizeBox, progBox, pctBox, undefined, undefined, uploadBtn );
}

// Null to avoid leaks in IE
Expand All @@ -1275,7 +1276,7 @@ ss.SimpleUpload.prototype = {
// No way to get status and statusText for an iframe so return empty strings
self._finish( '', '', response, filename, sizeBox, progBox, pctBox, undefined, undefined, uploadBtn );
} catch ( e ) {
self._errorFinish( '', e.message, 'error', filename, sizeBox, progBox, pctBox, undefined, undefined, uploadBtn );
self._errorFinish( '', e.message, false, 'error', filename, sizeBox, progBox, pctBox, undefined, undefined, uploadBtn );
}

ss.remove( iframe );
Expand Down
Loading