Skip to content

Commit 14c94fe

Browse files
committed
refactor: Remove exceptions from RooHandler constructor
- RooHandler constructor no longer throws RooAuthenticationError - Removed RooAuthenticationError class entirely - Authentication errors now handled by provider-proxy server (401 responses) - Removed pre-flight authentication check from ClineProvider.createTask - Updated webviewMessageHandler to handle generic errors instead of RooAuthenticationError - Client gracefully handles server error responses This change ensures provider constructors never throw exceptions, delegating all error handling to the server level for better separation of concerns.
1 parent 0bc1183 commit 14c94fe

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
143143
case "io-intelligence":
144144
return new IOIntelligenceHandler(options)
145145
case "roo":
146+
// Never throw exceptions from provider constructors
147+
// The provider-proxy server will handle authentication and return appropriate error codes
146148
return new RooHandler(options)
147149
case "featherless":
148150
return new FeatherlessHandler(options)

src/api/providers/roo.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@ import { CloudService } from "@roo-code/cloud"
44

55
import type { ApiHandlerOptions } from "../../shared/api"
66
import { ApiStream } from "../transform/stream"
7-
import { t } from "../../i18n"
87

98
import type { ApiHandlerCreateMessageMetadata } from "../index"
109
import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider"
1110

1211
export class RooHandler extends BaseOpenAiCompatibleProvider<RooModelId> {
1312
constructor(options: ApiHandlerOptions) {
14-
// Check if CloudService is available and get the session token.
15-
if (!CloudService.hasInstance()) {
16-
throw new Error(t("common:errors.roo.authenticationRequired"))
17-
}
18-
19-
const sessionToken = CloudService.instance.authService?.getSessionToken()
13+
// Get the session token if available, but don't throw if not.
14+
// The server will handle authentication errors and return appropriate status codes.
15+
let sessionToken = ""
2016

21-
if (!sessionToken) {
22-
throw new Error(t("common:errors.roo.authenticationRequired"))
17+
if (CloudService.hasInstance()) {
18+
sessionToken = CloudService.instance.authService?.getSessionToken() || ""
2319
}
2420

21+
// Always construct the handler, even without a valid token.
22+
// The provider-proxy server will return 401 if authentication fails.
2523
super({
2624
...options,
2725
providerName: "Roo Code Cloud",
2826
baseURL: process.env.ROO_CODE_PROVIDER_URL ?? "https://api.roocode.com/proxy/v1",
29-
apiKey: sessionToken,
27+
apiKey: sessionToken || "unauthenticated", // Use a placeholder if no token
3028
defaultProviderModelId: rooDefaultModelId,
3129
providerModels: rooModels,
3230
defaultTemperature: 0.7,

src/core/webview/webviewMessageHandler.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,24 @@ export const webviewMessageHandler = async (
288288
// Initializing new instance of Cline will make sure that any
289289
// agentically running promises in old instance don't affect our new
290290
// task. This essentially creates a fresh slate for the new task.
291-
await provider.createTask(message.text, message.images)
291+
try {
292+
await provider.createTask(message.text, message.images)
293+
// Task created successfully - notify the UI to reset
294+
await provider.postMessageToWebview({
295+
type: "invoke",
296+
invoke: "newChat",
297+
})
298+
} catch (error) {
299+
// For all errors, reset the UI and show error
300+
await provider.postMessageToWebview({
301+
type: "invoke",
302+
invoke: "newChat",
303+
})
304+
// Show error to user
305+
vscode.window.showErrorMessage(
306+
`Failed to create task: ${error instanceof Error ? error.message : String(error)}`,
307+
)
308+
}
292309
break
293310
case "customInstructions":
294311
await provider.updateCustomInstructions(message.text)

0 commit comments

Comments
 (0)