mirror of
https://github.com/cline/cline.git
synced 2026-09-16 21:01:52 +08:00
Fix error handling
This commit is contained in:
+2
-2
@@ -124,12 +124,12 @@
|
||||
"when": "view == claude-dev.SidebarProvider"
|
||||
},
|
||||
{
|
||||
"command": "cline.settingsButtonClicked",
|
||||
"command": "cline.accountLoginClicked",
|
||||
"group": "navigation@5",
|
||||
"when": "view == claude-dev.SidebarProvider"
|
||||
},
|
||||
{
|
||||
"command": "cline.accountLoginClicked",
|
||||
"command": "cline.settingsButtonClicked",
|
||||
"group": "navigation@6",
|
||||
"when": "view == claude-dev.SidebarProvider"
|
||||
}
|
||||
|
||||
@@ -274,25 +274,12 @@ export const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifi
|
||||
}
|
||||
|
||||
if (apiRequestFailedMessage) {
|
||||
try {
|
||||
const startIndex = apiRequestFailedMessage.indexOf("{")
|
||||
const endIndex = apiRequestFailedMessage.lastIndexOf("}")
|
||||
if (startIndex !== -1 && endIndex !== -1) {
|
||||
const jsonStr = apiRequestFailedMessage.substring(startIndex, endIndex + 1)
|
||||
const errorData = JSON.parse(jsonStr)
|
||||
if (
|
||||
errorData.code === "insufficient_credits" &&
|
||||
typeof errorData.current_balance === "number" &&
|
||||
typeof errorData.total_spent === "number" &&
|
||||
typeof errorData.total_promotions === "number" &&
|
||||
typeof errorData.message === "string"
|
||||
) {
|
||||
return <span style={{ color: errorColor, fontWeight: "bold" }}>Credit Limit Reached</span>
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Not JSON or missing required fields, fall back to default error display
|
||||
}
|
||||
// const errorData = parseErrorText(apiRequestFailedMessage)
|
||||
// if (errorData) {
|
||||
// if (errorData.code === "insufficient_credits") {
|
||||
// return <span style={{ color: errorColor, fontWeight: "bold" }}>Credit Limit Reached</span>
|
||||
// }
|
||||
// }
|
||||
return <span style={{ color: errorColor, fontWeight: "bold" }}>API Request Failed</span>
|
||||
}
|
||||
|
||||
@@ -779,32 +766,23 @@ export const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifi
|
||||
<>
|
||||
{(() => {
|
||||
// Try to parse the error message as JSON for credit limit error
|
||||
if (apiRequestFailedMessage) {
|
||||
const startIndex = apiRequestFailedMessage.indexOf("{")
|
||||
const endIndex = apiRequestFailedMessage.lastIndexOf("}")
|
||||
if (startIndex !== -1 && endIndex !== -1) {
|
||||
try {
|
||||
const jsonStr = apiRequestFailedMessage.substring(startIndex, endIndex + 1)
|
||||
const errorData = JSON.parse(jsonStr)
|
||||
if (
|
||||
errorData.code === "insufficient_credits" &&
|
||||
typeof errorData.current_balance === "number" &&
|
||||
typeof errorData.total_spent === "number" &&
|
||||
typeof errorData.total_promotions === "number" &&
|
||||
typeof errorData.message === "string"
|
||||
) {
|
||||
return (
|
||||
<CreditLimitError
|
||||
currentBalance={errorData.current_balance}
|
||||
totalSpent={errorData.total_spent}
|
||||
totalPromotions={errorData.total_promotions}
|
||||
message={errorData.message}
|
||||
/>
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
// Not valid JSON or missing required fields, fall back to default error display
|
||||
}
|
||||
const errorData = parseErrorText(apiRequestFailedMessage)
|
||||
if (errorData) {
|
||||
if (
|
||||
errorData.code === "insufficient_credits" &&
|
||||
typeof errorData.current_balance === "number" &&
|
||||
typeof errorData.total_spent === "number" &&
|
||||
typeof errorData.total_promotions === "number" &&
|
||||
typeof errorData.message === "string"
|
||||
) {
|
||||
return (
|
||||
<CreditLimitError
|
||||
currentBalance={errorData.current_balance}
|
||||
totalSpent={errorData.total_spent}
|
||||
totalPromotions={errorData.total_promotions}
|
||||
message={errorData.message}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1305,3 +1283,20 @@ const Markdown = memo(({ markdown }: { markdown?: string }) => {
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
function parseErrorText(text: string | undefined) {
|
||||
if (!text) {
|
||||
return undefined
|
||||
}
|
||||
try {
|
||||
const startIndex = text.indexOf("{")
|
||||
const endIndex = text.lastIndexOf("}")
|
||||
if (startIndex !== -1 && endIndex !== -1) {
|
||||
const jsonStr = text.substring(startIndex, endIndex + 1)
|
||||
const errorObject = JSON.parse(jsonStr)
|
||||
return errorObject
|
||||
}
|
||||
} catch (e) {
|
||||
// Not JSON or missing required fields
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,21 +17,22 @@ const CreditLimitError: React.FC<CreditLimitErrorProps> = ({ currentBalance, tot
|
||||
borderRadius: "4px",
|
||||
marginBottom: "12px",
|
||||
}}>
|
||||
<div style={{ marginBottom: "8px" }}>
|
||||
<div style={{ color: "var(--vscode-errorForeground)", marginBottom: "8px" }}>{message}</div>
|
||||
<div style={{ marginBottom: "12px" }}>
|
||||
<div style={{ color: "var(--vscode-foreground)" }}>
|
||||
Current Balance: <span style={{ fontWeight: "bold" }}>${currentBalance.toFixed(2)}</span>
|
||||
</div>
|
||||
<div style={{ color: "var(--vscode-foreground)" }}>Total Spent: ${totalSpent.toFixed(2)}</div>
|
||||
<div style={{ color: "var(--vscode-foreground)" }}>Total Promotions: ${totalPromotions.toFixed(2)}</div>
|
||||
</div>
|
||||
<div style={{ color: "var(--vscode-errorForeground)", marginBottom: "12px" }}>{message}</div>
|
||||
|
||||
<VSCodeButtonLink
|
||||
href="https://app.cline.bot/credits"
|
||||
style={{
|
||||
width: "100%",
|
||||
}}>
|
||||
<span className="codicon codicon-credit-card" style={{ fontSize: "14px", marginRight: "6px" }} />
|
||||
Buy Cline Credits
|
||||
Buy Credits
|
||||
</VSCodeButtonLink>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user