Making WordPress.org

Changeset 7750


Ignore:
Timestamp:
10/19/2018 08:06:43 PM (6 years ago)
Author:
iandunn
Message:

Meetup Client: Retry misleading 200 responses with empty bodies.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/utilities/class-meetup-client.php

    r7638 r7750  
    8484                    $this->error->add(
    8585                        'unexpected_response_data',
    86                         'The API response did not provide the expected data format.'
     86                        'The API response did not provide the expected data format.',
     87                        $response
    8788                    );
    8889                    break;
     
    169170         * See https://www.meetup.com/meetup_api/docs/#errors.
    170171         *
     172         * `200` (ok) is not in the list, because it needs to be handled conditionally. See below.
     173         *
    171174         * `400` (bad request) is not in the list, even though it seems like it _should_ indicate an unrecoverable
    172175         * error. In practice we've observed that it's common for a seemingly valid request to be rejected with
     
    174177         */
    175178        $breaking_codes = array(
    176             200, // Ok.
    177179            401, // Unauthorized (invalid key).
    178180            429, // Too many requests (rate-limited).
     
    190192
    191193            $this->maybe_throttle( wp_remote_retrieve_headers( $response ) );
     194
     195            /*
     196             * Sometimes their API inexplicably returns a success code with an empty body, but will return a valid
     197             * response if the exact request is retried.
     198             */
     199            if ( 200 === $response_code && ! empty( wp_remote_retrieve_body( $response ) ) ) {
     200                break;
     201            }
    192202
    193203            if ( in_array( $response_code, $breaking_codes, true ) ) {
Note: See TracChangeset for help on using the changeset viewer.