@@ -126,19 +126,36 @@ describe('search page', () => {
126126 fetch . mockResolvedValue ( {
127127 ok : false ,
128128 status : 503 ,
129- json : ( ) => Promise . resolve ( {
130- error : 'Search index is temporarily unavailable ' ,
131- code : 'SEARCH_INDEX_UNAVAILABLE ' ,
132- } ) ,
129+ text : ( ) => Promise . resolve ( JSON . stringify ( {
130+ error : 'Claude projects directory is not accessible ' ,
131+ code : 'SEARCH_PROJECTS_UNAVAILABLE ' ,
132+ } ) ) ,
133133 } ) ;
134134 document . getElementById ( 'search-input' ) . value = 'fail' ;
135135
136136 await doSearch ( ) ;
137137
138138 const err = document . querySelector ( '.search-error' ) ;
139139 expect ( err ) . not . toBeNull ( ) ;
140- expect ( err . getAttribute ( 'data-error-code' ) ) . toBe ( 'SEARCH_INDEX_UNAVAILABLE' ) ;
141- expect ( err . textContent ) . toContain ( 'temporarily unavailable' ) ;
140+ expect ( err . getAttribute ( 'data-error-code' ) ) . toBe ( 'SEARCH_PROJECTS_UNAVAILABLE' ) ;
141+ expect ( err . textContent ) . toContain ( 'not accessible' ) ;
142+ } ) ;
143+
144+ it ( 'doSearch shows plain-text error body when response is not JSON' , async ( ) => {
145+ showSearchPage ( ) ;
146+ fetch . mockResolvedValue ( {
147+ ok : false ,
148+ status : 502 ,
149+ text : ( ) => Promise . resolve ( 'Bad Gateway from proxy' ) ,
150+ } ) ;
151+ document . getElementById ( 'search-input' ) . value = 'fail' ;
152+
153+ await doSearch ( ) ;
154+
155+ const err = document . querySelector ( '.search-error' ) ;
156+ expect ( err ) . not . toBeNull ( ) ;
157+ expect ( err . textContent ) . toBe ( 'Bad Gateway from proxy' ) ;
158+ expect ( err . getAttribute ( 'data-error-code' ) ) . toBeNull ( ) ;
142159 } ) ;
143160
144161 it ( 'doSearch ignores stale responses when a newer request was started' , async ( ) => {
0 commit comments