Class FormFieldException
- All Implemented Interfaces:
Serializable
You can safely throw FormFieldException
from within your validator functions, and the
field name will automatically be propagated into the exception object for you.
The way that field names work is a bit complicated, because we need to support complex nested
field names like foo[3].bar
. So what happens is the original exception will be thrown by
a FormField
validator without the field set. Then as the exception bubbles up the stack,
it'll be caught by the convert
method, which then prepends the
name of that component. Then when the exception reaches the user, the getFieldName()
method will produce the fully-qualified field name.
This propagation mechanism is also very important when writing FormField.Builder.transform(java.lang.Class<T>, java.util.function.Function<O, T>)
functions, which oftentimes will not know the name of the field
they're validating.
- See Also:
-
Constructor Summary
ConstructorDescriptionFormFieldException
(FormField<?, ?> field, String userMessage) Creates a newFormFieldException
for a particular form field.FormFieldException
(String userMessage) Creates a newFormFieldException
FormFieldException
(String field, String userMessage) Creates a newFormFieldException
for a particular field name.FormFieldException
(String userMessage, Throwable cause) Creates a newFormFieldException
-
Method Summary
Methods inherited from class google.registry.ui.forms.FormException
getMessage
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Constructor Details
-
FormFieldException
Creates a newFormFieldException
This exception should only be thrown from within a
FormField
converter function. The field name will automatically be propagated into the exception object for you.- Parameters:
userMessage
- should be a friendly message that's safe to show to the user.
-
FormFieldException
Creates a newFormFieldException
This exception should only be thrown from within a
FormField
converter function. The field name will automatically be propagated into the exception object for you.- Parameters:
userMessage
- should be a friendly message that's safe to show to the user.cause
- the original cause of this exception (non-null).
-
FormFieldException
Creates a newFormFieldException
for a particular form field.This exception should only be thrown from within a
FormField
MAP converter function in situations where you're performing additional manual validation.- Parameters:
userMessage
- should be a friendly message that's safe to show to the user.
-
FormFieldException
Creates a newFormFieldException
for a particular field name.- Parameters:
field
- name corresponding to aFormField.name()
userMessage
- friendly message that's safe to show to the user
-
-
Method Details
-
getFieldName
Returns the fully-qualified name (JavaScript syntax) of the form field causing this error. -
propagate
Returns self withname
prepended, for propagating exceptions up the stack.This would be package-private except that it needs to be called by a test class in another package.
-
equals
-
hashCode
public int hashCode() -
toString
-