Export (0) Print
Expand All

Error Handling

System_CLiX_note Note

Atlas is now part of Facebook. To access Atlas API documentation, please click here.

The Creative Management API throws a FaultException<ApplicationFault> exception for errors that are related to the API. The ApplicationFault object is the base class for AdApiFaultDetail and AgencyServicesFault exceptions.

AdApiFaultDetail Exceptions

When a general API error occurs, a FaultException<AdApiFaultDetail> exception is thrown. This type of exception typically occurs during authentication to the Creative Management API web service. The FaultException.Detail element contains the AdApiFaultDetail object. The AdApiFaultDetail.Errors element specifies an array of AdApiError objects that contains more specific error information.

AgencyServicesFault Exceptions

When an error occurs that is specific to a Creative Management API service operation, a FaultException<AgencyServicesFault> is thrown. The FaultException.Detail object contains the AgencyServicesFault object. The AgencyServicesFault object contains an OperationErrors element and a BatchErrors element, described as follows:

  • Operation errors are used to track errors that occur during a service operation.

  • Batch errors are used to track errors that occur when processing arrays.

The OperationErrors element contains an array of OperationError objects, and the BatchErrors element contains an array of BatchError objects. Each object in both arrays has a Code element that specifies the type of error by using an error code. The Error Codes topic contains a list of the applicable error codes.

Code Example

The following code example shows how to use the AdApiFaultDetail and AgencyServicesFault exceptions to obtain details about the errors that occurred while attempting to perform a Creative Management API service operation.

try
{
    // Processing code.

}
// These errors are typically related to authentication.
catch (FaultException<AdApiFaultDetail> adApiFault)
{
    // Get the AdApiFaultDetail object.
    AdApiFaultDetail detail = adApiFault.Detail;

    // Report the error information to the console.
    foreach (AdApiError error in detail.Errors)
    {
        Console.WriteLine("\nAd API Fault Encountered.");
        Console.WriteLine("\tError Code: {0}", error.Code);
        Console.WriteLine("\t   Message: {0}", error.Message);
    }
}
// Capture errors that are specific to an
// Atlas Creative Management API service
// operation.
catch (FaultException<AgencyServicesFault> agencyFault)
{
    // Get the AgencyServicesFault object.
    AgencyServicesFault detail = agencyFault.Detail;

    // Check to see if there are operation errors.
    if (detail.OperationErrors != null)
    {
        foreach (OperationError opError in detail.OperationErrors)
        {
            Console.WriteLine("\nOperation Error Encountered.");
            Console.WriteLine("\tError Code: {0}", opError.Code);
            Console.WriteLine("\t   Message: {0}", opError.Message);
        }
    }

    // Check to see if there are batch errors.
    if (detail.BatchErrors != null)
    {
        foreach (BatchError bError in detail.BatchErrors)
        {
            Console.WriteLine("\nBatch Error Encountered.");
            Console.WriteLine("\tError Index: {0}", bError.Index);
            Console.WriteLine("\t       Code: {0}", bError.Code);
            Console.WriteLine("\t    Message: {0}", bError.Message);
        }
    }
}
// Capture exceptions on the client that are unrelated
// to the Creative Management API; for example, an
// out-of-memory condition on the client.
catch (Exception e)
{
    Console.WriteLine("Error '{0}' encountered.",
        e.Message);
}

For more information about errors in the Creative Management API, see Error ReferenceHow to Process Errors In RMT Ads in C#

Show:
© 2014 Microsoft