@@ -71,28 +71,38 @@ async function getValidSearchCredentials() {
7171}
7272
7373async function atomicCoveo ( ) {
74- await customElements . whenDefined ( 'atomic-search-interface' ) ;
75- const credentials = await getValidSearchCredentials ( ) ;
76-
77- document . querySelectorAll ( 'atomic-search-interface' ) . forEach ( async ( el ) => {
78- await el . initialize ( {
79- ...credentials ,
80- analytics : { analyticsMode : 'legacy' } ,
81- preprocessRequest : ( request ) => {
82- const body = JSON . parse ( request . body ) ;
83- body . q = `<@- ${ body . q } -@>` ;
84- request . body = JSON . stringify ( body ) ;
85- return request ;
86- } ,
74+ try {
75+ await customElements . whenDefined ( 'atomic-search-interface' ) ;
76+ const credentials = await getValidSearchCredentials ( ) ;
77+
78+ document . querySelectorAll ( 'atomic-search-interface' ) . forEach ( async ( el ) => {
79+ await el . initialize ( {
80+ ...credentials ,
81+ analytics : { analyticsMode : 'legacy' } ,
82+ preprocessRequest : ( request ) => {
83+ const body = JSON . parse ( request . body ) ;
84+ body . q = `<@- ${ body . q } -@>` ;
85+ request . body = JSON . stringify ( body ) ;
86+ return request ;
87+ } ,
88+ } ) ;
89+
90+ // No standalone searchboxes should be getting executing first search.
91+ if ( el . id === 'search-v2' ) await el . executeFirstSearch ( ) ;
8792 } ) ;
8893
89- // No standalone searchboxes should be getting executing first search.
90- if ( el . id === 'search-v2' ) await el . executeFirstSearch ( ) ;
91- } ) ;
92-
93- const headerSearchBar = document . querySelector ( '#search-standalone-header' ) ;
94- if ( headerSearchBar ?. shadowRoot ) {
95- hideShadowElement ( headerSearchBar . shadowRoot , 'atomic-relevance-inspector' ) ;
94+ const headerSearchBar = document . querySelector ( '#search-standalone-header' ) ;
95+ if ( headerSearchBar ?. shadowRoot ) {
96+ hideShadowElement (
97+ headerSearchBar . shadowRoot ,
98+ 'atomic-relevance-inspector'
99+ ) ;
100+ }
101+ } catch ( error ) {
102+ // Handle coveo error from only a LACK of credentials.
103+ // INCORRECT credentials will cause the page to load but spin waiting.
104+ const coveoErrorContainer = document . getElementById ( 'coveo-error-content' ) ;
105+ coveoErrorContainer . style . display = 'block' ;
96106 }
97107}
98108
0 commit comments