@@ -37,26 +37,46 @@ export const GET = withRouteHandler(async (_request: NextRequest) => {
3737 return NextResponse . json ( { models : [ ] } )
3838 }
3939
40- try {
41- logger . info ( 'Fetching Ollama models' , {
42- host : OLLAMA_HOST ,
43- } )
40+ logger . info ( 'Fetching Ollama models' , {
41+ host : OLLAMA_HOST ,
42+ } )
4443
45- const response = await fetch ( `${ OLLAMA_HOST } /api/tags` , {
44+ let response : Response
45+ try {
46+ response = await fetch ( `${ OLLAMA_HOST } /api/tags` , {
4647 headers : {
4748 'Content-Type' : 'application/json' ,
4849 } ,
4950 next : { revalidate : 60 } ,
5051 } )
52+ } catch ( error ) {
53+ /**
54+ * Ollama is optional, so a deployment that does not run one refuses the
55+ * connection on every poll. That is an expected state rather than a failure of
56+ * this route — the same condition its siblings report when `VLLM_BASE_URL` or
57+ * `LITELLM_BASE_URL` is absent — and the response is the same empty list a
58+ * blacklisted provider returns.
59+ *
60+ * Scoped to the connection itself: a server that answers but answers wrongly is
61+ * a real fault and is reported as one below.
62+ */
63+ logger . info ( 'Ollama service is not reachable, returning empty models' , {
64+ error : getErrorMessage ( error , 'Unknown error' ) ,
65+ host : OLLAMA_HOST ,
66+ } )
5167
52- if ( ! response . ok ) {
53- logger . warn ( 'Ollama service is not available' , {
54- status : response . status ,
55- statusText : response . statusText ,
56- } )
57- return NextResponse . json ( { models : [ ] } )
58- }
68+ return NextResponse . json ( { models : [ ] } )
69+ }
70+
71+ if ( ! response . ok ) {
72+ logger . warn ( 'Ollama service is not available' , {
73+ status : response . status ,
74+ statusText : response . statusText ,
75+ } )
76+ return NextResponse . json ( { models : [ ] } )
77+ }
5978
79+ try {
6080 const data = ollamaUpstreamResponseSchema . parse ( await response . json ( ) )
6181 const allModels = data . models . map ( ( model ) => model . name )
6282 const models = filterBlacklistedModels ( allModels )
@@ -69,14 +89,8 @@ export const GET = withRouteHandler(async (_request: NextRequest) => {
6989
7090 return NextResponse . json ( providerModelsResponseSchema . parse ( { models } ) )
7191 } catch ( error ) {
72- /**
73- * Ollama is optional, so a deployment that does not run one refuses the
74- * connection on every poll. That is an expected state rather than a failure of
75- * this route — the same condition its siblings report when `VLLM_BASE_URL` or
76- * `LITELLM_BASE_URL` is absent — and the response is the same empty list a
77- * blacklisted provider returns.
78- */
79- logger . info ( 'Ollama service is not reachable, returning empty models' , {
92+ /** Something is listening and returned 2xx, but not an Ollama tag listing. */
93+ logger . error ( 'Ollama returned a response this route cannot read' , {
8094 error : getErrorMessage ( error , 'Unknown error' ) ,
8195 host : OLLAMA_HOST ,
8296 } )
0 commit comments