Making WordPress.org


Ignore:
Timestamp:
06/11/2018 11:25:40 PM (8 years ago)
Author:
coreymckrill
Message:

Official WordPress Events: More info on remote_get error

The remote_get method is occasionally returning a 400 error, but the response
body seems to be empty. This adds the response message to the error report
in the hopes that it will provide a clue as to why these are happening.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/official-wordpress-events/official-wordpress-events.php

    r6824 r7292  
    628628                        $this->maybe_pause( wp_remote_retrieve_headers( $response ) );
    629629
     630                        $response_code    = wp_remote_retrieve_response_code( $response );
     631                        $response_message = wp_remote_retrieve_response_message( $response );
     632                        $response_body    = wp_remote_retrieve_body( $response );
     633
    630634                        if ( is_wp_error( $response ) ) {
    631635                                $error_messages = implode( ', ', $response->get_error_messages() );
     
    639643                                        );
    640644                                }
    641                         } elseif ( 200 != $response['response']['code'] ) {
     645                        } elseif ( 200 != $response_code ) {
    642646                                // trigger_error() has a message limit of 1024 bytes, so we truncate $response['body'] to make sure that $body doesn't get truncated.
    643 
    644647                                $error = sprintf(
    645                                         'Received HTTP code: %s and body: %s. Request was to: %s; Arguments were: %s',
    646                                         $response['response']['code'],
    647                                         substr( sanitize_text_field( $response['body'] ), 0, 500 ),
     648                                        "HTTP Code: %d\nMessage: %s\nBody: %s\nRequest URL: %s\nArgs: %s",
     649                                        $response_code,
     650                                        sanitize_text_field( $response_message ),
     651                                        substr( sanitize_text_field( $response_body ), 0, 500 ),
    648652                                        $url,
    649653                                        print_r( $args, true )
    650654                                );
    651655
    652                                 $response = new WP_Error( 'woe_invalid_http_response', 'Invalid HTTP response code', $response );
     656                                $response = new WP_Error( 'owe_invalid_http_response', 'Invalid HTTP response code', $response );
    653657                        }
    654658
    655659                        if ( $error ) {
    656660                                $error = preg_replace( '/&key=[a-z0-9]+/i', '&key=[redacted]', $error );
    657                                 trigger_error( sprintf( '%s error for %s: %s', __METHOD__, parse_url( site_url(), PHP_URL_HOST ), sanitize_text_field( $error ) ), E_USER_WARNING );
     661                                trigger_error( sprintf(
     662                                        '%s error for %s: %s',
     663                                        __METHOD__,
     664                                        parse_url( site_url(), PHP_URL_HOST ),
     665                                        sanitize_text_field( $error )
     666                                ), E_USER_WARNING );
    658667
    659668                                $to = apply_filters( 'owe_error_email_addresses', array() );
    660669                                if ( $to && ( ! defined( 'WPORG_SANDBOXED_REQUEST' ) || ! WPORG_SANDBOXED_REQUEST ) ) {
    661                                         wp_mail( $to, sprintf( '%s error for %s', __METHOD__, parse_url( site_url(), PHP_URL_HOST ) ), sanitize_text_field( $error ) );
     670                                        wp_mail(
     671                                                $to,
     672                                                sprintf(
     673                                                        '%s error for %s',
     674                                                        __METHOD__,
     675                                                        parse_url( site_url(), PHP_URL_HOST )
     676                                                ),
     677                                                sanitize_text_field( $error )
     678                                        );
    662679                                }
    663680                        }
Note: See TracChangeset for help on using the changeset viewer.