mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-27 06:15:15 +00:00
fix(raycast): surface API error details (#1709)
This commit is contained in:
parent
848e5ac369
commit
bbe05bd9e4
2 changed files with 24 additions and 8 deletions
19
apps/raycast-extension/src/api-error.ts
Normal file
19
apps/raycast-extension/src/api-error.ts
Normal 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
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue