Mailchimp_Helpers::check_for_errors( mixed $response )

check_for_errors


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'] );
		}
	}