Add 404 response to REST response for invalid note ID (https://github.com/woocommerce/woocommerce-admin/pull/1194)

This commit is contained in:
Joshua T Flowers 2018-12-28 09:51:22 +08:00 committed by GitHub
parent a0f23c93c9
commit e0596ea249
1 changed files with 9 additions and 0 deletions

View File

@ -76,6 +76,15 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller {
*/
public function get_item( $request ) {
$note = WC_Admin_Notes::get_note( $request->get_param( 'id' ) );
if ( ! $note ) {
return new WP_Error(
'woocommerce_admin_notes_invalid_id',
__( 'Sorry, there is no resouce with that ID.', 'wc-admin' ),
array( 'status' => 404 )
);
}
if ( is_wp_error( $note ) ) {
return $note;
}