Better openrouter error handling (#1945)

This commit is contained in:
Matt Rubens 2025-03-24 11:36:50 -04:00 committed by GitHub
parent 83ba22a44c
commit 30f9d8f032
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1227,7 +1227,16 @@ export class Cline extends EventEmitter<ClineEvents> {
} 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