src/HookListener/HttpApiListener.php
private function log_http_error( $data, $context, $class, array $args = [], $url = '' ) {

		$msg      = 'WP HTTP API Error';
		$response = is_array( $data ) && isset( $data[ 'response' ] ) && is_array( $data[ 'response' ] )
			? shortcode_atts( [ 'message' => '', 'code' => '', 'body' => '' ], $data[ 'response' ] )
			: [ 'message' => '', 'code' => '', 'body' => '' ];

		if ( is_wp_error( $data ) ) {
			$msg .= ': ' . $data->get_error_message();
		} elseif ( is_string( $response[ 'message' ] ) && $response[ 'message' ] ) {
			$msg .= ': ' . $response[ 'message' ];
		}

		$log_context = [
			'transport'  => $class,
			'context'    => $context,
			'query_args' => $args,
			'url'        => $url,
		];

		if ( $response[ 'body' ] && is_string( $response[ 'body' ] ) ) {
			$log_context[ 'response_body' ] = strlen( $response[ 'body' ] ) <= 300
				? $response[ 'body' ]
				: substr( $response[ 'body' ], 0, 300 ) . '...';
		}

		if ( array_key_exists( 'code', $response ) && is_scalar( $response[ 'code' ] ) ) {
			$msg .= " - Response code: {$response[ 'code' ]}";
			( is_array( $data ) && ! empty( $data[ 'headers' ] ) ) and $log_context[ 'headers' ] = $data[ 'headers' ];
		}

		return new Error( rtrim( $msg, '.' ) . '.', Channels::HTTP, $log_context );
	}
private function log_http_error( $data, $context, $class, array $args = [], $url = '' ) {

		$msg      = 'WP HTTP API Error';
		$response = is_array( $data ) && isset( $data[ 'response' ] ) && is_array( $data[ 'response' ] )
			? shortcode_atts( [ 'message' => '', 'code' => '', 'body' => '' ], $data[ 'response' ] )
			: [ 'message' => '', 'code' => '', 'body' => '' ];

		if ( is_wp_error( $data ) ) {
			$msg .= ': ' . $data->get_error_message();
		} elseif ( is_string( $response[ 'message' ] ) && $response[ 'message' ] ) {
			$msg .= ': ' . $response[ 'message' ];
		}

		$log_context = [
			'transport'  => $class,
			'context'    => $context,
			'query_args' => $args,
			'url'        => $url,
		];

		if ( $response[ 'body' ] && is_string( $response[ 'body' ] ) ) {
			$log_context[ 'response_body' ] = strlen( $response[ 'body' ] ) <= 300
				? $response[ 'body' ]
				: substr( $response[ 'body' ], 0, 300 ) . '...';
		}

		if ( array_key_exists( 'code', $response ) && is_scalar( $response[ 'code' ] ) ) {
			$msg .= " - Response code: {$response[ 'code' ]}";
			( is_array( $data ) && ! empty( $data[ 'headers' ] ) ) and $log_context[ 'headers' ] = $data[ 'headers' ];
		}

		return new Error( rtrim( $msg, '.' ) . '.', Channels::HTTP, $log_context );
	}
private function log_http_error ( $ data , $ context , $ class , array $ args = [ ] , $ url = '' ) { $ msg = 'WP HTTP API Error' ; $ response = is_array ( $ data ) && isset ( $ data [ 'response' ] ) && is_array ( $ data [ 'response' ] ) ? shortcode_atts ( [ 'message' => '' , 'code' => '' , 'body' => '' ] , $ data [ 'response' ] ) : [ 'message' => '' , 'code' => '' , 'body' => '' ] ; if ( is_wp_error ( $ data ) ) { $ msg .= ': ' . $ data -> get_error_message ( ) ; } elseif ( is_string ( $ response [ 'message' ] ) && $ response [ 'message' ] ) { $ msg .= ': ' . $ response [ 'message' ] ; } $ log_context = [ 'transport' => $ class , 'context' => $ context , 'query_args' => $ args , 'url' => $ url , ] ; if ( $ response [ 'body' ] && is_string ( $ response [ 'body' ] ) ) { $ log_context [ 'response_body' ] = strlen ( $ response [ 'body' ] ) <= 300 ? $ response [ 'body' ] : substr ( $ response [ 'body' ] , 0 , 300 ) . '...' ; } if ( array_key_exists ( 'code' , $ response ) && is_scalar ( $ response [ 'code' ] ) ) { $ msg .= " - Response code: {$response[ 'code' ]}" ; ( is_array ( $ data ) && ! empty ( $ data [ 'headers' ] ) ) and $ log_context [ 'headers' ] = $ data [ 'headers' ] ; } return new Error ( rtrim ( $ msg , '.' ) . '.' , Channels :: HTTP , $ log_context ) ; }
Log any error for HTTP API.

@param \WP_Error|array $data
@param string          $context
@param string          $class
@param array           $args
@param string          $url

@return Error
Log any error for HTTP API .