Customized Error Messages

Highlighted
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
Highlighted
Frequent Participant

Hi, Error codes can be found

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/

Highlighted
Occasional Participant

One more hint...

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...

Highlighted
Frequent Participant

Hi, Yes that appears to be

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

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured