fix(raycast): surface API error details (#1709)

This commit is contained in:
vivekvar-dl 2026-10-12 22:13:40 -07:00 • committed by Mahesh Sanikommu
parent 848e5ac369
commit bbe05bd9e4
2 changed files with 24 additions and 8 deletions

View file

@ -0,0 +1,19 @@
export function extractApiErrorMessage(raw: string): string | undefined {
const body = raw.trim()
if (!body) return undefined
try {
const parsed: unknown = JSON.parse(body)
if (parsed && typeof parsed === "object") {
const error = Reflect.get(parsed, "error")
if (typeof error === "string" && error.trim()) return error
const message = Reflect.get(parsed, "message")
if (typeof message === "string" && message.trim()) return message
}
} catch {
return body
}
return undefined
}

View file

@ -1,4 +1,5 @@
import { getPreferenceValues, showToast, Toast } from "@raycast/api"
import { extractApiErrorMessage } from "./api-error"
export interface Project {
id: string
@ -101,14 +102,10 @@ async function makeAuthenticatedRequest<T>(
}
let errorMessage = `API request failed: ${response.statusText}`
try {
const errorBody = (await response.json()) as { message?: string }
if (errorBody.message) {
errorMessage = errorBody.message
}
} catch {
// Ignore JSON parsing errors, use default message
}
const responseMessage = extractApiErrorMessage(
await response.text().catch(() => ""),
)
if (responseMessage) errorMessage = responseMessage
throw new SupermemoryAPIError(errorMessage, response.status)
}