Hi Play Team,
I'm learning Play in my side project. I have a code like this:
Long userId = 0L;
try {
String user = tokenGenerator.getUserNameForToken(token);
//other code over here
} catch (SignatureException e) {
//should be an authentication error message
}
if(userId != 0)
return dashBoardService.createDashBoard().handle(((userdataRecord, throwable) -> {
ObjectNode response = Json.newObject();
response.put("success","true");
return ok(response);
}));
else
{
//pass on the authentication error message
//in catch block as a response
}
The above code should return the type `CompletionStage<Result>`. Since the call to getUserNameForToken may throw exception, I need to handle that as well as success case. I'm not sure how one should send an dummy CompletionStage just to mock for an error (which is actually captured in the catch block).
May be I'm doing it wrong someway or there should be a common pattern for the same.