Skip to content

Commit

Permalink
Use WP_Error.
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedmonkey committed Jun 12, 2020
1 parent bf404fb commit 07c7c24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions assets/src/media-selector/views/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ const Button = wp.media.view.Button.extend( {
this.options.click.apply( this, arguments );
}
} )
.catch( () => {
.catch( error => {
this.$el.attr( 'disabled', false ); // Enable button.
spinner.hide();
const errors = getConfig( 'errors' );
alert( errors.generic ); // eslint-disable-line
if ( error && error.responseJSON && error.responseJSON.message ) {
alert( error.responseJSON.message.replace( /(<([^>]+)>)/gi, '' ) ); // eslint-disable-line
} else {
const errors = getConfig( 'errors' );
alert( errors ); // eslint-disable-line
}
} );
},
} );
Expand Down
4 changes: 2 additions & 2 deletions php/class-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function get_import( $request ) {

$api_response = $this->plugin->api->get( $id );
if ( is_wp_error( $api_response ) ) {
return $this->rest_ensure_response( $api_response, $request );
return $api_response;
}
$results = $api_response->get_results();
$credentials = $this->plugin->settings->get_credentials();
Expand All @@ -237,7 +237,7 @@ public function get_import( $request ) {
$importer = new Import( $id, $image );
$attachment_id = $importer->process();
if ( is_wp_error( $attachment_id ) ) {
return $this->rest_ensure_response( $attachment_id, $request );
return $attachment_id;
}
$this->plugin->api->download( $id );
$response = $this->prepare_item_for_response( $results, $request );
Expand Down

0 comments on commit 07c7c24

Please sign in to comment.