@@ -54,28 +54,35 @@ async def validate_form_or_throw_error(
54
54
async def validate_form_fields_or_throw_error (
55
55
config_form_fields : List [NormalisedFormField ], form_fields_raw : Any
56
56
) -> List [FormField ]:
57
- if form_fields_raw is None :
58
- raise_bad_input_exception ("Missing input param: formFields" )
57
+ try :
58
+ if form_fields_raw is None :
59
+ raise_bad_input_exception ("Missing input param: formFields" )
59
60
60
- if not isinstance (form_fields_raw , List ):
61
- raise_bad_input_exception ("formFields must be an array" )
61
+ if not isinstance (form_fields_raw , List ):
62
+ raise_bad_input_exception ("formFields must be an array" )
62
63
63
- form_fields : List [FormField ] = []
64
+ form_fields : List [FormField ] = []
64
65
65
- form_fields_list_raw : List [Dict [str , Any ]] = form_fields_raw
66
- for current_form_field in form_fields_list_raw :
67
- if (
68
- "id" not in current_form_field
69
- or not isinstance (current_form_field ["id" ], str )
70
- or "value" not in current_form_field
71
- ):
72
- raise_bad_input_exception (
73
- "All elements of formFields must contain an 'id' and 'value' field"
74
- )
75
- value = current_form_field ["value" ]
76
- if current_form_field ["id" ] == FORM_FIELD_EMAIL_ID :
77
- value = value .strip ()
78
- form_fields .append (FormField (current_form_field ["id" ], value ))
66
+ form_fields_list_raw : List [Dict [str , Any ]] = form_fields_raw
67
+ for current_form_field in form_fields_list_raw :
68
+ if (
69
+ "id" not in current_form_field
70
+ or not isinstance (current_form_field ["id" ], str )
71
+ or "value" not in current_form_field
72
+ ):
73
+ raise_bad_input_exception (
74
+ "All elements of formFields must contain an 'id' and 'value' field"
75
+ )
76
+ value = current_form_field ["value" ]
77
+ if current_form_field ["id" ] == FORM_FIELD_EMAIL_ID :
78
+ if not isinstance (value , str ):
79
+ raise_bad_input_exception ("email value must be a string" )
80
+ value = value .strip ()
81
+ form_fields .append (FormField (current_form_field ["id" ], value ))
79
82
80
- await validate_form_or_throw_error (form_fields , config_form_fields )
81
- return form_fields
83
+ await validate_form_or_throw_error (form_fields , config_form_fields )
84
+ return form_fields
85
+ except Exception :
86
+ raise_bad_input_exception (
87
+ "Something seems wrong with the input formFields. Please check the request body."
88
+ )
0 commit comments