Handle a multi-object API error

Multi-object APIs use return objects that contain an array of return status objects and a global return status object. The array of return status objects describes the errors that prevent individual objects from being processed. The global return status object describes the errors that prevent all objects from being processed. When you use multi-object APIs, your application should examine both the array of return status objects and the global return status object.
  1. Invoke the multiple-object method and check the global return status object for errors.
    createUserResponse createUserResponse = coreWebService.createUser(createUserRequest);
    CreateUserResult createUserResult = createUserResponse.returnValue;
    if (createUserResult.createUserReturnStatus.code != CreateUserReturnStatusEnumType.SUCCESS)
    {
  2. Verify that the error is not a server-side error. For example, the BlackBerry® Enterprise Server that hosts a component you are trying to use is unavailable.
         if (createUserResult.createUserReturnStatus.actor.Equals("server") == "true") 
         {
               //notify the user that the server cannot process the request
         }
  3. Check the return status object for each user object.
       for (int count=0; count<createUsersResult.createUsersReturnResult.Length; count++)
      {
  4. Depending on how much information or error handling you want to provide, perform one of the following actions:
    1. To display the error description provided by the BlackBerry® Administration API, use the message attribute.
           System.Console.WriteLine(createUserResult.createUserReturnStatus[count].message);
    2. To display more detailed information or instructions to your user, check for each error code listed in the <MethodName>ReturnStatusEnumType class in the API reference. For example, see the CreateUserReturnStatusEnumType class in the API reference for a list of of the error codes in the createUser() method.
           if (createUsersResult.createUserReturnStatus[count].code == CreateUserReturnStatusEnumType.UNKNOWN)
           {
               // handle error
           } else if (createUsersResult.createUserReturnStatus[count].code == CreateUserReturnStatusEnumType.NOT_AUTHORIZED)
           {
               // handle error
           } else if (createUsersResult.createUserReturnStatus[count].code == CreateUserReturnStatusEnumType.RESULT_ERROR_EXISTS)
           {
               // handle error
           } else if (createUsersResult.createUserReturnStatus[count].code == CreateUserReturnStatusEnumType.INVALID_PARAMETER)
           {
               // handle error
           } else if (createUsersResult.createUserReturnStatus[count].code == CreateUserReturnStatusEnumType.TARGET_SERVICE_INSTANCE_NOT_RUNNING)
           {
               // handle error
           } else if (createUsersResult.createUserReturnStatus[count].code == CreateUserReturnStatusEnumType.USER_ALREADY_BLACKBERRY_ENABLED)
           {
               // handle error
           } else if (createUsersResult.createUserReturnStatus[count].code == CreateUserReturnStatusEnumType.COULD_NOT_ENABLE_DELETE_BLACKBERRY_USER)
           {
               // handle error
           } else if (createUsersResult.createUserReturnStatus[count].code == CreateUserReturnStatusEnumType.CANNOT_ADD_USER_TO_GROUP)
           {
               // handle error
           } else if (createUsersResult.createUserReturnStatus[count].code == CreateUserReturnStatusEnumType.CANNOT_ATTACH_ITPOLICY_TO_USER)
           {
               // handle error
           } else if (createUsersResult.createUserReturnStatus[count].code == CreateUserReturnStatusEnumType.CANNOT_ATTACH_SOFTWARE_CONFIGURATION_TO_USER)
           {
               // handle error
           } 
  5. Close if and for statements.
       }
    }

Was this information helpful? Send us your comments.