Customized Error Messages

Occasional Participant

Customized Error Messages

How would I go about customizing the error messages returned by the API (in PHP)? I'm using the sample forms, and want to conditionally specify the message in this chunk of code:


if (isset($error)) {

                    if ($error === true) {

                        echo "<p>".$error."</p>";

                        $class = "error";

                        $message = $ccOBJ->lastError;

                    }

                else {

                    $class = "success";

                    $message = "Contact ".$_POST." Added.";

                }

                    echo '<div class="'.$class.'">';

                    echo $message;

                    echo '</div>';

                }

 


Is there a way to get the error code from the $ccOBJ? I want to give a descriptive sentence for each possible error message that might be returned by CC.

3 REPLIES 3
Regular Participant

Hi,


Error codes can be found here:


http://developer.constantcontact.com/doc/errorCodes


If you know PHP fairly well you could modify the code so curl saves the HTTP response code, all you will need to do is compare it to that list above and apply your own error messages depending on the context in which they occur.


Hope that helps.

James Benson, PHP Developer.


Constant Contact Services: http://integrationservic.es/

Occasional Participant

I know about the error codes list, but do you mean something like this?


$http = curl_init($url);

$result = curl_exec($http);

$http_status = curl_getinfo($http, CURLINFO_HTTP_CODE);

echo $http_status;


Would I place this after I bring in the CC include? How would I get the value of $url?


I can handle setting up the error messages if I only could get to the point where I have a variable with the HTTP response code...

Regular Participant

Hi,


Yes that appears to be correct but I've not tested it personally.


Since you are using a PHP class you can create variables within that class.


eg. $this->http_status = curl_getinfo($http, CURLINFO_HTTP_CODE);


Then you can access that variable inside your class eg. echo $this->http_status;


or outside your class eg. echo $cc->http_status;


Hope that helps.


 

James Benson, PHP Developer.


Constant Contact Services: http://integrationservic.es/

Developer Portal

View API documentation, code samples, get your API key.

Visit Page