Skip to content

Commit

Permalink
Merge pull request #383 from twinnydotdev/development
Browse files Browse the repository at this point in the history
development > main
  • Loading branch information
rjmacarthy authored Nov 11, 2024
2 parents 8d24ff3 + 337dada commit f4229a4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "twinny",
"displayName": "twinny - AI Code Completion and Chat",
"description": "Locally hosted AI code completion plugin for vscode",
"version": "3.18.11",
"version": "3.18.12",
"icon": "assets/icon.png",
"keywords": [
"code-inference",
Expand Down
8 changes: 8 additions & 0 deletions src/extension/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export async function streamResponse(request: StreamRequest) {
const controller = new AbortController()
const { signal } = controller

const timeOut = setTimeout(() => {
controller.abort()
onError?.(new Error("Request timed out"))
}, 25000)

try {
const url = `${options.protocol}://${options.hostname}${options.port ? `:${options.port}` : ""}${options.path}`
const fetchOptions = {
Expand All @@ -18,6 +23,7 @@ export async function streamResponse(request: StreamRequest) {
}

const response = await fetch(url, fetchOptions)
clearTimeout(timeOut)

if (!response.ok) {
throw new Error(`Server responded with status code: ${response.status}`)
Expand Down Expand Up @@ -77,12 +83,14 @@ export async function streamResponse(request: StreamRequest) {
onEnd?.()
reader.releaseLock()
} catch (error: unknown) {
clearTimeout(timeOut)
controller.abort()
if (error instanceof Error) {
if (error.name === "AbortError") {
onEnd?.()
} else {
console.error("Fetch error:", error)
onError?.(error)
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/extension/review-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ export class GithubService extends ConversationHistory {
})
this._completion = ""
},
onError: (error: Error) => {
this.webView?.postMessage({
type: EVENT_NAME.twinnyOnEnd,
value: {
error: true,
errorMessage: error.message,
},
} as ServerMessage)
}
})
} catch (e) {
return reject(e)
Expand Down

0 comments on commit f4229a4

Please sign in to comment.