mirror of
https://github.com/Dvorinka/Primora.git
synced 2026-10-28 15:51:23 +00:00
- api-client: getResponseBody returns Blob for non-JSON (fixes storage preview/download TypeError); postgen.mjs reapplies the patch on regen - Modal: error prop renders inside the dialog so request failures are visible instead of hidden behind the overlay (6 pages wired) - lib/api: extract server-provided error message from error.body - Modal: unique id per instance (duplicate modal-title broke aria-label) - nginx: index.html no-cache + immutable /assets (stale shell pointed at deleted hashed assets after redeploy → white screen) - vite: drop dead Google Fonts runtime caching (fonts are vendored) - functions: audit function.created/updated/deleted/invoked - AuditPage: expand action filter to all recorded actions - MCP: whoami uses /context for API keys; projectId/orgId resolve via /context with auth-aware precedence (stale `primora use` selection can never authorize a differently-scoped key) Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { OpenAPI } from "@primora/api-client";
|
|
|
|
import { fetchApiToken } from "./auth-client";
|
|
|
|
OpenAPI.BASE = import.meta.env.VITE_API_BASE_URL ?? "/api/v1";
|
|
// encodeURI leaves ?#& intact in path params — smuggles query segments.
|
|
OpenAPI.ENCODE_PATH = encodeURIComponent;
|
|
OpenAPI.CREDENTIALS = "include";
|
|
OpenAPI.WITH_CREDENTIALS = true;
|
|
OpenAPI.TOKEN = async () => (await fetchApiToken()) ?? "";
|
|
|
|
export function configureApiToken(tokenResolver?: () => Promise<string | undefined>) {
|
|
OpenAPI.TOKEN = tokenResolver ? async () => (await tokenResolver()) ?? "" : async () => (await fetchApiToken()) ?? "";
|
|
}
|
|
|
|
/**
|
|
* Extracts a human-readable message from an API failure.
|
|
* ApiError.message is only the HTTP status text ("Bad Request") — the backend
|
|
* sends the actionable reason in body.error.message. Prefer it.
|
|
*/
|
|
export function errorMessage(error: unknown, fallback = "Request failed"): string {
|
|
if (error && typeof error === "object") {
|
|
const body = (error as { body?: { error?: { message?: unknown } } }).body;
|
|
if (typeof body?.error?.message === "string" && body.error.message.length > 0) {
|
|
return body.error.message;
|
|
}
|
|
const message = (error as { message?: unknown }).message;
|
|
if (typeof message === "string" && message.length > 0) return message;
|
|
}
|
|
return fallback;
|
|
}
|