Making WordPress.org

Changeset 12513


Ignore:
Timestamp:
03/29/2023 06:31:21 PM (3 years ago)
Author:
amieiro
Message:

Translate: Check if the DeepL API response is 200

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/routes/class-translation-memory.php

    r12510 r12513  
    207207        if ( is_wp_error( $deepl_response ) ) {
    208208            return array();
    209         } else {
    210             $body                             = wp_remote_retrieve_body( $deepl_response );
    211             $response['deepl']['translation'] = json_decode( $body )->translations[0]->text;
    212             $response['deepl']['diff']        = '';
    213             $this->update_deepl_chars_used( $original_singular );
    214             return $response;
    215         }
     209        }
     210        $response_status = wp_remote_retrieve_response_code( $deepl_response );
     211        if ( 200 !== $response_status ) {
     212            return array();
     213        }
     214        $body                             = wp_remote_retrieve_body( $deepl_response );
     215        $response['deepl']['translation'] = json_decode( $body )->translations[0]->text;
     216        $response['deepl']['diff']        = '';
     217        $this->update_deepl_chars_used( $original_singular );
     218        return $response;
    216219    }
    217220
Note: See TracChangeset for help on using the changeset viewer.