From 30f9d8f0324a9ff316cab5aa7863dac980696950 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Mon, 24 Mar 2025 11:36:50 -0400 Subject: [PATCH] Better openrouter error handling (#1945) --- src/core/Cline.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 81cdd671fc..010d86e94e 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -1227,7 +1227,16 @@ export class Cline extends EventEmitter { } catch (error) { // note that this api_req_failed ask is unique in that we only present this option if the api hasn't streamed any content yet (ie it fails on the first chunk due), as it would allow them to hit a retry button. However if the api failed mid-stream, it could be in any arbitrary state where some tools may have executed, so that error is handled differently and requires cancelling the task entirely. if (alwaysApproveResubmit) { - const errorMsg = error.error?.metadata?.raw ?? error.message ?? "Unknown error" + let errorMsg + + if (error.error?.metadata?.raw) { + errorMsg = JSON.stringify(error.error.metadata.raw, null, 2) + } else if (error.message) { + errorMsg = error.message + } else { + errorMsg = "Unknown error" + } + const baseDelay = requestDelaySeconds || 5 const exponentialDelay = Math.ceil(baseDelay * Math.pow(2, retryAttempt)) // Wait for the greater of the exponential delay or the rate limit delay