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.
    createUserResponse createUserResponse = coreWebService.createUser(createUserRequest);
    CreateUserResult createUserResult = createUserResponse.returnValue;
    if (createUserResult.createUserReturnStatus.code != 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.createUserReturnStatus.actor.ToUpper().Equals("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.Console.WriteLine(createUserResult.createUserReturnStatus.message);
    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.createUserReturnStatus.code == CreateUserReturnStatusEnumType.UNKNOWN)
           {
               // handle error
           } else if (createUserResult.createUserReturnStatus.code == CreateUserReturnStatusEnumType.NOT_AUTHORIZED)
           {
               // handle error
           } else if (createUserResult.createUserReturnStatus.code == CreateUserReturnStatusEnumType.RESULT_ERROR_EXISTS)
           {
               // handle error
           } else if (createUserResult.createUserReturnStatus.code == CreateUserReturnStatusEnumType.INVALID_PARAMETER)
           {
               // handle error
           } else if (createUserResult.createUserReturnStatus.code == CreateUserReturnStatusEnumType.TARGET_SERVICE_INSTANCE_NOT_RUNNING)
           {
               // handle error
           } else if (createUserResult.createUserReturnStatus.code == CreateUserReturnStatusEnumType.USER_ALREADY_BLACKBERRY_ENABLED)
           {
               // handle error
           } else if (createUserResult.createUserReturnStatus.code == CreateUserReturnStatusEnumType.COULD_NOT_ENABLE_DELETE_BLACKBERRY_USER)
           {
               // handle error
           } else if (createUserResult.createUserReturnStatus.code == CreateUserReturnStatusEnumType.CANNOT_ADD_USER_TO_GROUP)
           {
               // handle error
           } else if (createUserResult.createUserReturnStatus.code == CreateUserReturnStatusEnumType.CANNOT_ATTACH_ITPOLICY_TO_USER)
           {
               // handle error
           } else if (createUserResult.createUserReturnStatus.code == 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.