How to get results of API calls in CBL

I’m trying to assign a user role using CBL and I know that async calls spawning another thread are no longer supported in CBL.









Backendless.UserService.assignRole("test@test.com", "TestingSubscribers", new AsyncCallback<Void>() {




			@Override

			public void handleResponse(Void arg0) {

				debug("TestAssignUserRoleTimer#assignRole: handleResponse succeed: " + arg0);

			}




			@Override

			public void handleFault(BackendlessFault backendlessFault) {

				error("TestAssignUserRoleTimer#assignRole error: " 

						+ backendlessFault.getMessage()

						+ " (" + backendlessFault.getCode() + "): "

						+ backendlessFault.getDetail()

						);

			}

		});

so of course I get this error:

11/27/15 6:10 PM ERROR com.backendless.digitalcopel.timers.TestAssignUserRoleTimer TestAssignUserRoleTimer#assignRole error: You have no permission to thread manipulation (IllegalArgumentException): null

so I know the solution is to use Backendless.UserService.assignRole("test@test.com", “TestingSubscribers”);

but I want to know the result of the call, i.e. whether it succeeded or failed. How can I do this in CBL?

Forgot to add, is doing a try { } catch the only way to check for errors?

Hi, Simon.

Have you tried logging the result?

@Override 
public void execute( String appVersionId ) throws Exception 
{ 
 LogBuffer.getInstance().setLogReportingPolicy( 1, 0 ); 
 Logger log = Logger.getLogger( YOUR_CLASS.class ); 
 
 try  
 { 
 Backendless.UserService.assignRole("test@test.com", "TestingSubscribers"); ; 
 log.info( "Role assigned"); 
 } 
 catch ( Throwable t ) 
 { 
 log.error( "Error assigning role", t ); 
 throw new RuntimeException( t ); 
 } 
} 



Regards,
Artur.

Hi,

I see, this is the new way to use the Logging service. Excellent.
I guess I have an older version of CodeRunner installed because Backendless.UserService.assignRole is a void function that doesn’t return anything. I’ll try this! Thanks,
Simon.

Hi, Simon,

It truly returns void, I have updated my answer.

Good luck,
Artur.