Skip to content

Commit

Permalink
Task: Handle http errors better
Browse files Browse the repository at this point in the history
  • Loading branch information
zya committed Oct 25, 2023
1 parent e0e8813 commit 71cd932
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/handlers/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ export async function OllamaHandler(

const res = await getOllamaResponse(model, prompt, baseUrl);

if (!res.ok) {
throw new Error(
`Recieved an error with code ${res.status} from Ollama API.`,
);
}

if (params.stream) {
return iterateResponse(res, model, prompt);
}
Expand Down
6 changes: 6 additions & 0 deletions src/handlers/ollamaEmbedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export async function OllamaEmbeddingHandler(
const model = params.model.split('ollama/')[1];
const baseUrl = params.baseUrl ?? 'http://127.0.0.1:11434';
const response = await getOllamaResponse(model, params.input, baseUrl);

if (!response.ok) {
throw new Error(
`Recieved an error with code ${response.status} from Ollama API.`,
);
}
const body = (await response.json()) as OllamaEmbeddingsResponseChunk;

return {
Expand Down

0 comments on commit 71cd932

Please sign in to comment.