Includes request ID in error returned by Cline API (#4909)
* Includes request ID in error returned by Cline API Adding the request ID to error messages to aid in debugging for users. * Use constant for auth error message; revert change from previous PR * Fix webview auth status if null/undefined user is passed in auth status message * Create nasty-parents-play.md --------- Co-authored-by: abeatrix <beatrix@cline.bot> Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
This commit is contained in:
6 files changed
+31
-13
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
Includes request ID in error returned by Cline API
|
||||
@@ -11,6 +11,7 @@ import { AuthService } from "@/services/auth/AuthService"
|
||||
import OpenAI from "openai"
|
||||
import { version as extensionVersion } from "../../../package.json"
|
||||
import { shouldSkipReasoningForModel } from "@utils/model-utils"
|
||||
import { CLINE_ACCOUNT_AUTH_ERROR_MESSAGE } from "@/shared/ClineAccount"
|
||||
|
||||
interface ClineHandlerOptions {
|
||||
taskId?: string
|
||||
@@ -42,7 +43,7 @@ export class ClineHandler implements ApiHandler {
|
||||
private async ensureClient(): Promise<OpenAI> {
|
||||
const clineAccountAuthToken = await this._authService.getAuthToken()
|
||||
if (!clineAccountAuthToken) {
|
||||
throw new Error("Cline account authentication token is required")
|
||||
throw new Error(CLINE_ACCOUNT_AUTH_ERROR_MESSAGE)
|
||||
}
|
||||
if (!this.client) {
|
||||
try {
|
||||
@@ -183,13 +184,19 @@ export class ClineHandler implements ApiHandler {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.code === "ERR_BAD_REQUEST" || error.status === 401) {
|
||||
throw new Error("Unauthorized: Please sign in to Cline before trying again.") // match with webview-ui/src/components/chat/ChatRow.tsx
|
||||
} else if (error.code === "insufficient_credits" || error.status === 402) {
|
||||
throw new Error(error.error ? JSON.stringify(error.error) : "Insufficient credits or unknown error.")
|
||||
}
|
||||
console.error("Cline API Error:", error)
|
||||
throw error instanceof Error ? error : new Error(String(error))
|
||||
const requestId = error?.request_id ? ` (Request ID: ${error.request_id})` : ""
|
||||
if (error.code === "ERR_BAD_REQUEST" || error.status === 401) {
|
||||
throw new Error(CLINE_ACCOUNT_AUTH_ERROR_MESSAGE + requestId)
|
||||
} else if (error.code === "insufficient_credits" || error.status === 402) {
|
||||
if (error.error) {
|
||||
error.error.message = error.error.message + requestId
|
||||
throw new Error(JSON.stringify(error.error))
|
||||
}
|
||||
}
|
||||
const _error = error instanceof Error ? error : new Error(String(error))
|
||||
_error.message = _error.message + requestId
|
||||
throw _error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,3 +76,6 @@ export interface OrganizationUsageTransaction {
|
||||
totalTokens: number
|
||||
userId: string
|
||||
}
|
||||
|
||||
// Used in cline.ts provider and in webview-ui/src/components/chat/ChatRow.tsx to display the login button
|
||||
export const CLINE_ACCOUNT_AUTH_ERROR_MESSAGE = "Unauthorized: Please sign in to Cline before trying again."
|
||||
@@ -37,6 +37,7 @@ import ReportBugPreview from "./ReportBugPreview"
|
||||
import UserMessage from "./UserMessage"
|
||||
import QuoteButton from "./QuoteButton"
|
||||
import { useClineAuth } from "@/context/ClineAuthContext"
|
||||
import { CLINE_ACCOUNT_AUTH_ERROR_MESSAGE } from "@shared/ClineAccount"
|
||||
|
||||
const normalColor = "var(--vscode-foreground)"
|
||||
const errorColor = "var(--vscode-errorForeground)"
|
||||
@@ -1008,9 +1009,7 @@ export const ChatRowContent = memo(
|
||||
.
|
||||
</>
|
||||
)}
|
||||
{apiRequestFailedMessage?.includes(
|
||||
"Unauthorized: Please sign in to Cline before trying again.", // match with cline.ts (TODO: remove after some time)
|
||||
) && (
|
||||
{apiRequestFailedMessage?.includes(CLINE_ACCOUNT_AUTH_ERROR_MESSAGE) && (
|
||||
<>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
@@ -25,7 +25,7 @@ const CreditLimitError: React.FC<CreditLimitErrorProps> = ({
|
||||
<div className="mb-2">{message}</div>
|
||||
<div className="mb-3">
|
||||
<div className="text-[var(--vscode-foreground)]">
|
||||
Current Balance: <span className="font-bold">${(currentBalance / 1000000).toFixed(4)}</span>
|
||||
Current Balance: <span className="font-bold">${currentBalance.toFixed(4)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -30,8 +30,12 @@ export const ClineAuthProvider: React.FC<{ children: React.ReactNode }> = ({ chi
|
||||
const cancelSubscription = AccountServiceClient.subscribeToAuthStatusUpdate(EmptyRequest.create(), {
|
||||
onResponse: async (response: any) => {
|
||||
console.log("Extension: ClineAuthContext: Received auth status update:", response)
|
||||
if (response && response.user) {
|
||||
setUser(response.user)
|
||||
if (response) {
|
||||
if (response.user) {
|
||||
setUser(response.user)
|
||||
} else {
|
||||
setUser(null)
|
||||
}
|
||||
}
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
|
||||
Reference in new issue
Block a user