Throw a more useful error message on attempted domain restore reports (#145)

* Throw a more useful error message on attempted domain restore reports

Per DomainRestoreRequestFlow's Javadoc, we automatically approve and instantly
enact all domain restore requests, thus we don't use or support restore
reports. This improves the registrar-visible error message to help make this
more clear.
This commit is contained in:
Ben McIlwain
2019-07-02 14:11:37 -04:00
committed by GitHub
parent 0e8724a48f
commit 07239710ef
4 changed files with 72 additions and 3 deletions
@@ -209,6 +209,7 @@ public abstract class EppException extends Exception {
/** Specified command is not implemented. */
@EppResultCode(Code.UNIMPLEMENTED_COMMAND)
public static class UnimplementedCommandException extends EppException {
public UnimplementedCommandException(InnerCommand command) {
super(String.format(
"No flow found for %s with extension %s",
@@ -217,6 +218,10 @@ public abstract class EppException extends Exception {
? ((ResourceCommandWrapper) command).getResourceCommand().getClass().getSimpleName()
: null));
}
public UnimplementedCommandException(String message) {
super(message);
}
}
/** Abstract exception class. Do not throw this directly or catch in tests. */
@@ -82,6 +82,9 @@ public class FlowPicker {
/** Marker class for unimplemented flows. */
private abstract static class UnimplementedFlow implements Flow {}
/** Marker class for unimplemented restore flows. */
private abstract static class UnimplementedRestoreFlow implements Flow {}
/** A function type that takes an {@link EppInput} and returns a {@link Flow} class. */
private abstract static class FlowProvider {
/** Get the flow associated with this {@link EppInput} or return null to signal no match. */
@@ -160,7 +163,7 @@ public class FlowPicker {
// Restore command with an op of "report" is not currently supported.
return (rgpUpdateExtension.get().getRestoreCommand().getRestoreOp() == RestoreOp.REQUEST)
? DomainRestoreRequestFlow.class
: UnimplementedFlow.class;
: UnimplementedRestoreFlow.class;
}};
/**
@@ -265,8 +268,11 @@ public class FlowPicker {
Class<? extends Flow> flowClass = flowProvider.get(eppInput);
if (flowClass == UnimplementedFlow.class) {
break; // We found it, but it's marked as not implemented.
}
if (flowClass != null) {
} else if (flowClass == UnimplementedRestoreFlow.class) {
throw new UnimplementedCommandException(
"Domain restores are approved and enacted instantly, "
+ "therefore domain restore reports are not supported");
} else if (flowClass != null) {
return flowClass; // We found it!
}
}