onError Callback

Overview

Sourcepoint has introduced a new error handling callback function called onError. The callback function is passed three parameters.

  • An error code (string) - the error code corresponds to one of five string values defined in the next section of this document.

  • An error object (object) - the JavaScript error object including the associated stack trace.

  • A user reset value (boolean) - whether the user ID was reset for this individual.

Error Code Definitions

The list of error codes passed to the function are below:

  • ACTION - The error came from an Action like a Custom Consent Action.

  • CHOICE - An error coming from an invalid choice action being provided to the script.

  • CMP_CALLBACK - An error thrown by the __tcfapi callback.

  • REQUEST - An error in the request sent to the Sourcepoint platform (i.e. a network error). In this case the user ID of the individual will be reset.

  • UNKNOWN - A generic unknown error occurred. In this case the user ID of the individual will be reset.

As noted above, the user ID of the site visitor will be reset when a REQUEST or an UNKNOWN error type occurs.

Example Code

Below is an example of a callback configured to write the errorCode, errorObject and userReset value to the developer console.

<script type="text/javascript">
//Stub function omitted for brevity
</script>
<script>
window._sp_ = {
config: {
accountId: ACCOUNT_ID,
wrapperAPIOrigin: "https://wrapper-api.sp-prod.net/tcfv2",
baseEndpoint: "https://cdn.privacy-mgmt.com",
events: {
onError: function (errorCode, errorObject, userReset){
console.log('errorCode: ' + errorCode);
console.log(errorObject);
console.log('userReset: ' + userReset);
}
}
}
}
</script>
<script src="https://cdn.privacy-mgmt.com/wrapperMessagingWithoutDetection.js">
</script>
‚Äč