MC4WP_API_Exception::__construct ( string $message, int $code, array $response = null, mixed $data = null )

MC4WP_API_Exception constructor.

Source file: api/class-exception.php

View source


Parameters

$message

(string) (Required)

$code

(int) (Required)

$response

(array) (Optional)

Default value: null

$data

(mixed) (Optional)

Default value: null


Uses


Source

    public function __construct( $message, $code, $response = null, $data = null ) {
        parent::__construct( $message, $code );

        $this->response = $response;

        if( ! empty( $data ) ) {
            // fill error properties from json data
            $error_properties = array( 'type', 'title', 'status', 'detail', 'instance', 'errors' );
            foreach( $error_properties as $key ) {
                if( ! empty( $data->$key ) ) {
                    $this->$key = $data->$key;
                }
            }

            // use MailChimp error as message
            if( ! empty( $data->detail ) ) {
                $this->message = $data->detail;
            }
        }
    }
}

User Contributed Notes

You must log in before being able to contribute a note.