Warning: Array to string conversion in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 825

Warning: foreach() argument must be of type array|object, string given in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 830

Warning: Array to string conversion in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 825
Mailchimp_Helpers::check_for_errors( mixed $response )

check_for_errors


Warning: foreach() argument must be of type array|object, string given in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 830

Warning: Array to string conversion in /home/customer/www/docs.automatorplugin.com/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 825

Parameters Parameters

$response

(Required)


Top ↑

Return Return

(void)


Source Source

File: src/integrations/mailchimp/helpers/mailchimp-helpers.php

	public function check_for_errors( $response ) {
		$expected_codes = array( 200, 204 );
		if ( in_array( $response['statusCode'], $expected_codes, true ) ) {
			return $response;
		}
		$error_msg = '';
		if ( isset( $response['data']['title'] ) ) {
			$error_msg .= $response['data']['title'];
		}
		if ( isset( $response['data']['detail'] ) ) {
			$error_msg .= ': ' . $response['data']['detail'];
		}
		if ( isset( $respons['data']['errors'] ) ) {
			foreach ( $response['data']['errors'] as $error ) {
				$error_msg .= ' ' . $error['field'];
				$error_msg .= ' ' . $error['message'];
			}
		}
		if ( ! empty( $error_msg ) ) {
			if ( isset( $response['statusCode'] ) ) {
				$error_msg = '(' . $response['statusCode'] . ') ' . $error_msg;
			}
			throw new \Exception( $error_msg, $response['statusCode'] );
		}
	}