Skip to content

Commit

Permalink
fixed displaying OpenAI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nk-o committed Jan 21, 2024
1 parent 4d0badb commit 98ee455
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions classes/class-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,11 @@ public function request_ai( WP_REST_Request $req ) {
);

// Error.
if ( is_wp_error( $ai_request ) || wp_remote_retrieve_response_code( $ai_request ) !== 200 ) {
if ( is_wp_error( $ai_request ) ) {
$response = $ai_request->get_error_message();

if ( $response ) {
return $this->error( 'openai_request_error', $response );
}

return $this->error( 'openai_request_error', $response );
} elseif ( wp_remote_retrieve_response_code( $ai_request ) !== 200 ) {
$response = json_decode( wp_remote_retrieve_body( $ai_request ), true );

if ( isset( $response['error']['message'] ) ) {
Expand Down

0 comments on commit 98ee455

Please sign in to comment.