Skip to content

Loqate Address Verifier – Detect Zero Credit OnLoad?

Using the Loqate Address Verification service, is there a way to programatically detect that your account is out of credit, on load of the control? Something like the code below (that I just made up)?

var controlToReturn = new pca.Address(fields, avOptions);
control.listen("load", function () {
   if (this.accountCredit == 0) {
      //do stuff

It’s possible to handle a zero credit error thrown by the control after you’ve used it, but at that point you’ve displayed an address search field, and then have to hide it, and fall back to a standard address form layout (in our case at least).

controlToReturn.listen("error", function (message) {    

   const ERROR_MESSAGE_ZERO_CREDIT = "Account out of credit";

   if (message != ERROR_MESSAGE_ZERO_CREDIT)
     alert("Error with address checker service: " + message);

There doesn’t seem to be anything in their docs, but I just wondered if anyone knew of any properties on the control / other API calls that would allow this?


The problem is that the Loqate address.js library, which calls their API, is not returning the whole error object, just the message.

This may not be an approach that is endorsed by Loqate, but you can access the original error object through the reference to the pca.Address in the ‘error’ listener.

You should be able to do this (in the ‘error’ listener function):

var errorCode = this.error.arguments[1].response.Items[0].Error;

‘arguments[1]’ is the pca.Request object that caused the error, and ‘Items[0]’ is the error object, which has the properties ‘Error’ (the code), ‘Description’, ‘Cause’ and ‘Resolution’.

Note that ‘errorCode’ is a string at this point, so you might also want to use parseInt on it.

The full list of error codes is available on the Loqate website. ‘Account out of credit’ is ‘3’, but there are a number of other errors that you may want to handle differently.