Skip to content

Commit

Permalink
Don't only rely on response code but also check actual content
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftner committed Nov 4, 2016
1 parent e388936 commit 1e724f2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions assets/src/logo/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,23 @@
// Bind event handler to file upload / drag&drop
uploader.bind( 'FileUploaded', function( up, file, response ) {

if ( 200 !== response.status ) {
return;
}
if ( 200 !== response.status ) {
return;
}

// Start C&P from handlers.js
// https://github.com/WordPress/WordPress/blob/32be6f7bb73b5c8e4bdd90179aa85b275606d982/wp-includes/js/plupload/handlers.js#L83-L87

var serverData = response.response;

// on success serverData should be numeric, fix bug in html4 runtime returning the serverData wrapped in a <pre> tag
serverData = serverData.replace(/^<pre>(\d+)<\/pre>$/, '$1');

// if async-upload returned an error message, place it in the media item div and return
if ( serverData.match(/media-upload-error|error-div/) ) {
return;
}
// End C&P from handlers.js

// Triggers Model:fetch( att_id ) & event listeners in the views
logo.set( { 'att_id' : response.response } );
Expand Down

0 comments on commit 1e724f2

Please sign in to comment.