11/**
22 * Type-safe HTML element selectors
33 */
4+ import { ClientScriptError } from '@components/scripts/errors/ClientScriptError'
45import {
56 isButtonElement ,
67 isDivElement ,
@@ -151,7 +152,9 @@ export class ContactFormSelectors {
151152 public get contactForm ( ) : HTMLFormElement {
152153 const formELement = document . querySelector ( SELECTORS . formELement )
153154 if ( ! isFormElement ( formELement ) ) {
154- throw new Error ( `Contact form is missing in document, selector: ${ SELECTORS . formELement } ` )
155+ throw new ClientScriptError ( {
156+ message : `Contact form is missing in document, selector: ${ SELECTORS . formELement } `
157+ } )
155158 }
156159 return formELement
157160 }
@@ -163,9 +166,9 @@ export class ContactFormSelectors {
163166 if ( ! this . _submitButton ) {
164167 const submitButton = document . querySelector ( SELECTORS . submitButton )
165168 if ( ! isButtonElement ( submitButton ) ) {
166- throw new Error (
167- `Contact form submit button is missing in document, selector: ${ SELECTORS . submitButton } `
168- )
169+ throw new ClientScriptError ( {
170+ message : `Contact form submit button is missing in document, selector: ${ SELECTORS . submitButton } `
171+ } )
169172 }
170173 this . _submitButton = submitButton
171174 }
@@ -179,7 +182,9 @@ export class ContactFormSelectors {
179182 if ( ! this . _formValidationError ) {
180183 const errorValidationElement = document . querySelector ( SELECTORS . formError )
181184 if ( ! isDivElement ( errorValidationElement ) ) {
182- throw new Error ( `Contact form error wrapper is missing in document: ${ SELECTORS . formError } ` )
185+ throw new ClientScriptError ( {
186+ message : `Contact form error wrapper is missing in document: ${ SELECTORS . formError } `
187+ } )
183188 }
184189 this . _formValidationError = errorValidationElement
185190 }
@@ -193,9 +198,9 @@ export class ContactFormSelectors {
193198 const elementSelector = SELECTORS [ selector ]
194199 const group = document . querySelector ( elementSelector )
195200 if ( ! isDivElement ( group ) ) {
196- throw new Error (
197- `Contact form input group wrapper <div> is missing in document, selector: ${ elementSelector } `
198- )
201+ throw new ClientScriptError ( {
202+ message : `Contact form input group wrapper <div> is missing in document, selector: ${ elementSelector } `
203+ } )
199204 }
200205 return group
201206 }
@@ -206,9 +211,9 @@ export class ContactFormSelectors {
206211 private getInputElement ( formGroup : HTMLDivElement ) : HTMLInputElement {
207212 const inputElement = formGroup . querySelector ( SELECTORS . inputElement )
208213 if ( ! isInputElement ( inputElement ) ) {
209- throw new Error (
210- `Contact form input element is missing in document for input group: ${ formGroup [ 'tagName' ] } `
211- )
214+ throw new ClientScriptError ( {
215+ message : `Contact form input element is missing in document for input group: ${ formGroup [ 'tagName' ] } `
216+ } )
212217 }
213218 return inputElement
214219 }
@@ -219,9 +224,9 @@ export class ContactFormSelectors {
219224 private getLabelElement ( formGroup : HTMLDivElement ) : HTMLLabelElement {
220225 const labelElement = formGroup . querySelector ( SELECTORS . inputLabel )
221226 if ( ! isLabelElement ( labelElement ) ) {
222- throw new Error (
223- `Contact form input group wrapper <div> is missing in document for input group: ${ formGroup [ 'tagName' ] } `
224- )
227+ throw new ClientScriptError ( {
228+ message : `Contact form input group wrapper <div> is missing in document for input group: ${ formGroup [ 'tagName' ] } `
229+ } )
225230 }
226231 return labelElement
227232 }
@@ -232,9 +237,9 @@ export class ContactFormSelectors {
232237 private getErrorValidationElement ( formGroup : HTMLDivElement ) : HTMLDivElement {
233238 const errorValidationElement = formGroup . querySelector ( SELECTORS . validationError )
234239 if ( ! isDivElement ( errorValidationElement ) ) {
235- throw new Error (
236- `Contact form input group wrapper <div> is missing in document for input group: ${ formGroup [ 'tagName' ] } `
237- )
240+ throw new ClientScriptError ( {
241+ message : `Contact form input group wrapper <div> is missing in document for input group: ${ formGroup [ 'tagName' ] } `
242+ } )
238243 }
239244 return errorValidationElement
240245 }
0 commit comments