if (remoteApp == null) {
return Promise.pure((Result) badRequest("can't extract registration request json"));
}
final AcHostModel acHost = AcHostModel.fromJson(remoteApp);
Promise<Void> hostRegistered = AC.registerHost(acHost);
Promise<Result> resultPromise = hostRegistered.map(new F.Function<Void, Result>() {
@Override
public Result apply(Void nada) throws Throwable {
return ok();
}
});
return resultPromise.recover(new F.Function<Throwable, Result>() {
@Override
public Result apply(Throwable throwable) throws Throwable {
LOGGER.warn("Failed to register host (key = " + acHost.getKey() + ")", throwable);
if (throwable instanceof PublicKeyVerificationFailureException) {
return internalServerError("failed to fetch public key from host for verification");
}
return badRequest("Unable to register host. Request invalid"); // TODO: better analysis of failure and feedback to caller