diff --git a/includes/Classifai/Providers/Azure/OCR.php b/includes/Classifai/Providers/Azure/OCR.php index acfd9bf7a..1b241a7f5 100644 --- a/includes/Classifai/Providers/Azure/OCR.php +++ b/includes/Classifai/Providers/Azure/OCR.php @@ -329,8 +329,15 @@ public function process( string $url ) { if ( ! is_wp_error( $response ) ) { $body = json_decode( wp_remote_retrieve_body( $response ) ); - if ( 200 !== wp_remote_retrieve_response_code( $response ) && isset( $body->message ) ) { + if ( isset( $body->message ) ) { + $error_message = $body->message; + } else if ( isset( $body->error->message ) ) { + $error_message = $body->error->message; + } else { + $error_message = false; + } + if ( 200 !== wp_remote_retrieve_response_code( $response ) && $error_message ) { /** * Fires when the ocr API response did not succeed. * @@ -342,7 +349,7 @@ public function process( string $url ) { */ do_action( 'classifai_ocr_unsuccessful_response', $response, $url ); - $rtn = new WP_Error( $body->code ?? 'error', $body->message, $body ); + $rtn = new WP_Error( $body->code ?? 'error', $error_message, $body ); } else { $rtn = $body; }