Error handling with InterFAX API
When using the InterFAX API, there may be situations where you would encounter an error. There are several types of errors that you may encounter:
Communication errors
These errors will occur due to a problem with reaching the InterFAX API endpoint (for example, using an incorrect endpoint URL).
- In order to properly process these errors, we would recommend that you encapsulate the code segment(s) relating to requests to InterFAX with an exception block and catch the exceptions as they occur.
Request submission errors
These errors will occur due to a problem with the request submitted to the API – it may be caused by incorrect request meta data or incorrect request body (for example, when providing an incorrect username or password).
- In order to properly process these errors, we would recommend that you create an object for the response sent back from InterFAX and process the status code that is returned (read more about our web service status codes)
Fax delivery errors
These errors will occur due a problem with the delivery of the fax (for example, if the recipient number has a busy signal).
- In order to properly processes these errors, we would recommend that you check the status of the fax and decide how to proceed based on that status (read more about fax status codes)
We recommend adding error handling at each stage of your code to address these issues and, based on the result of the error handling, decide if the code should proceed or not with the rest of the actions – for example, if the fax was not submitted to InterFAX due to an authentication error, then there is no need to perform a check on the status of the fax because a) the credentials will most likely still not work and b) there was no fax submitted and so no fax ID returned to you to search for. Below is a pseudo-code example to demonstrate error handling:
try
{
int response = sendFax(...);
if (response > 0)
{
object faxObject = checkStatus(...);
while (faxObject.status < 0)
{
wait(10);
faxObject = checkStatus(...);
}
if (faxObject.status = 0)
{
Display_Successful_Delivery_Message();
}
else
{
Display_Failed_Delivery_Message();
}
}
else
{
Display_Failed_Submission_Message();
}
}
catch (Exception NetworkException)
{
Display_Failed_Connection_Message();
}