Closed twooton61 closed 6 years ago
@twooton61
Below steps show how to get the errorresponse when response is null.
Step 1: Instantiate the controller that will call the service
var controller = new createCustomerProfileController(request);
controller.Execute();
Step 2: Get the response from the service (errors contained if any)
createCustomerProfileResponse response = controller.GetApiResponse();
Step 3: Validate response
if (response != null)
{
// Your code goes here
}
Step 4: If Response is null, then in else part, call the GetErrorResponse() method as shown below to get the error messages/response.
else
{
// Check for errors
ANetApiResponse errorResponse = controller.GetErrorResponse();
if (errorResponse.messages.message.Length > 0)
{
Console.WriteLine("Customer Profile Creation Failed.");
Console.WriteLine("Error Code: " + errorResponse.messages.message[0].code);
Console.WriteLine("Error message: " + errorResponse.messages.message[0].text);
}
else
{
Console.WriteLine("Null Response.");
}
}
Closing this based on the steps provided previously. Please feel free to re-open if further support needed on this issue.
A lot of the example code for this API shows checking for response.messages.resultCode to check for errors immediately after calling controller.GetApiResponse(). But with validation errors, the response is null. It was only after digging around in the API I found GetResultCode() and the actual error validation error in GetResults(). I wouldn't expect GetApiResponse() to return null on a validation error, but rather a response with response.messages.resultCode set to messageTypeEnum.Error and the relevant error messages in response.messages