--- layout: page title: Handling Errors ---

If an API call fails (SOAP fault or HTTP error), CampaignException object is thrown. This object contains the following attributes

In general all errors are mapped to a CampaignException and we try to keep the semantic of errors: for instance a call with an incorrect parameter will return an HTTP stauts of 400 even if it's not actually a, HTTP call. SDK specific errors will have an errorCode with the "SDK-######" format, using "SDK" as a prefix.

try {
  await client.logon();
  result = await NLWS.xtkSession.getServerTime();
} catch (ex) {
  /*
    CampaignException object
    ex.statusCode: the HTTP status code, such as 500, 404…
    ex.errorCode the Campaign error code (ex: XSV-350013)
    ex.faultCode the Campaign iRc or some other error code (ex: -53)
    ex.faultString the Error message
  */
  console.log(ex.message);  
}

It's also noteworthy that all the data returned in a CampaignException is trimmed, i.e. session and security token values are hidden, so that the exception object can be safely logged.

Note: The transport protocol returns errors of type HttpError which are wrapped into CampaignException objects.