Skip to content

Commit 8607c28

Browse files
authored
Fixed catch in abort examples (#128)
1 parent f73dae5 commit 8607c28

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

examples/abort/any-request.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ setTimeout(() => {
66
ollama.abort()
77
}, 1000) // 1000 milliseconds = 1 second
88

9-
try {
10-
ollama.generate({
9+
ollama.generate({
1110
model: 'llama3.1',
1211
prompt: 'Write a long story',
1312
stream: true,
@@ -17,11 +16,12 @@ try {
1716
process.stdout.write(chunk.response)
1817
}
1918
}
19+
).catch(
20+
(error) => {
21+
if (error.name === 'AbortError') {
22+
console.log('The request has been aborted')
23+
} else {
24+
console.error('An error occurred:', error)
25+
}
26+
}
2027
)
21-
} catch (error) {
22-
if (error.name === 'AbortError') {
23-
console.log('The request has been aborted')
24-
} else {
25-
console.error('An error occurred:', error)
26-
}
27-
}

examples/abort/specific-request.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ setTimeout(() => {
99
stream.abort()
1010
}, 1000) // 1000 milliseconds = 1 second
1111

12-
try {
13-
ollama.generate({
12+
ollama.generate({
1413
model: 'llama3.1',
1514
prompt: 'Write a long story',
1615
stream: true,
@@ -21,11 +20,12 @@ try {
2120
process.stdout.write(chunk.response)
2221
}
2322
}
23+
).catch(
24+
(error) => {
25+
if (error.name === 'AbortError') {
26+
console.log('The request has been aborted')
27+
} else {
28+
console.error('An error occurred:', error)
29+
}
30+
}
2431
)
25-
} catch (error) {
26-
if (error.name === 'AbortError') {
27-
console.log('The request has been aborted')
28-
} else {
29-
console.error('An error occurred:', error)
30-
}
31-
}

0 commit comments

Comments
 (0)