Don't throw an exception on orphaned contacts

Return Optional.absent() instead of throwing NotFoundException when a user has
a contact record but the Registrar entity is missing.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=138423965
This commit is contained in:
mmuller 2016-11-07 12:21:48 -08:00 committed by Ben McIlwain
parent 7a77819977
commit cbe76e8615
2 changed files with 16 additions and 2 deletions

View file

@ -24,6 +24,7 @@ import com.google.appengine.api.users.UserService;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.googlecode.objectify.Key;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.RegistrarContact;
import google.registry.util.FormattingLogger;
@ -121,7 +122,12 @@ public class SessionUtils {
if (contact == null) {
return Optional.absent();
}
return Optional.of(ofy().load().key(contact.getParent()).safe());
Optional<Registrar> result = Optional.fromNullable(ofy().load().key(contact.getParent()).now());
if (!result.isPresent()) {
logger.severefmt(
"A contact record exists for non-existent registrar: %s.", Key.create(contact));
}
return result;
}
/** @see #hasAccessToRegistrar(Registrar, String) */