Handle a single-object API error

Single-object APIs use return objects that contain a return status object of the type <MethodName>ReturnStatus, where MethodName is the name of the API method that your application called. The following code sample shows how you can handle the single-object API errors in the createUser() method.

  1. Invoke the single-object API and check to see if any errors occurred.
    CreateUserResult createUserResult = coreWebService.createUser(userEnableBBAttributes, locale, targetGroup, targetITPolicy, targetSoftwareConfiguration);        
    if (createUserResult.getCreateUserReturnStatus().getCode()!= CreateUserReturnStatusEnumType.SUCCESS) 
    {
  2. Verify that the error was not a server-side error. For example, the BlackBerry® Enterprise Server that hosts a component you are trying to use is unavailable.
          if (createUserResult.getCreateUserReturnStatus().getActor().equalsIgnoreCase("server"))
         {
               //notify the user that the server cannot process the request
         } 
  3. 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.out.println(createUserResult.getCreateUserReturnStatus().getMessage());            
    2. To display more detailed information or instructions to your user, check for each error code that is listed in the <MethodName>ReturnStatusEnumType class in the API reference. For example, see the CreateUserReturnStatusEnumType class in the API reference for a list of error codes in the createUser() method.
           if (createUserResult.getCreateUserReturnStatus().getCode() == CreateUserReturnStatusEnumType.UNKNOWN)
           {
               // handle error
           } else if (createUserResult.getCreateUserReturnStatus().getCode() == CreateUserReturnStatusEnumType.NOT_AUTHORIZED)
           {
               // handle error
           } else if (createUserResult.getCreateUserReturnStatus().getCode() == CreateUserReturnStatusEnumType.RESULT_ERROR_EXISTS)
           {
               // handle error
           } else if (createUserResult.getCreateUserReturnStatus().getCode() == CreateUserReturnStatusEnumType.INVALID_PARAMETER)
           {
               // handle error
           } else if (createUserResult.getCreateUserReturnStatus().getCode() == CreateUserReturnStatusEnumType.TARGET_SERVICE_INSTANCE_NOT_RUNNING)
           {
               // handle error
           } else if (createUserResult.getCreateUserReturnStatus().getCode() == CreateUserReturnStatusEnumType.USER_ALREADY_BLACKBERRY_ENABLED)
           {
               // handle error
           } else if (createUserResult.getCreateUserReturnStatus().getCode() == CreateUserReturnStatusEnumType.COULD_NOT_ENABLE_DELETE_BLACKBERRY_USER)
           {
               // handle error
           } else if (createUserResult.getCreateUserReturnStatus().getCode() == CreateUserReturnStatusEnumType.CANNOT_ADD_USER_TO_GROUP)
           {
               // handle error
           } else if (createUserResult.getCreateUserReturnStatus().getCode() == CreateUserReturnStatusEnumType.CANNOT_ATTACH_ITPOLICY_TO_USER)
           {
               // handle error
           } else if (createUserResult.getCreateUserReturnStatus().getCode() == CreateUserReturnStatusEnumType.CANNOT_ATTACH_SOFTWARE_CONFIGURATION_TO_USER)
           {
               // handle error
           } 
  4. Close the if statement.
    }
Previous topic: Handling errors

Was this information helpful? Send us your comments.