fix: close marketplace client review findings

This commit is contained in:
2026-08-28 21:01:51 +08:00
parent 8dfa542860
commit 1614f7efc1
25 changed files with 1224 additions and 143 deletions

View File

@@ -111,17 +111,22 @@ function telemetryRoute(path: string): string {
async function parseResponse<T>(response: Response): Promise<T> {
if (!response.ok) {
let message = `${response.status} ${response.statusText}`;
let backendCode: string | undefined;
try {
const payload = await response.json() as { error?: string };
const payload = await response.json() as { error?: string; code?: unknown };
if (payload?.error) {
message = payload.error;
}
if (typeof payload?.code === 'string' && /^[a-z][a-z0-9_]{0,63}$/u.test(payload.code)) {
backendCode = payload.code;
}
} catch {
// ignore body parse failure
}
throw normalizeAppError(new Error(message), {
source: 'browser-fallback',
status: response.status,
...(backendCode ? { backendCode } : {}),
});
}

View File

@@ -277,6 +277,13 @@ async function installationMutation(method: 'POST' | 'DELETE', segment: 'install
return parseMarketplaceInstallation(await fetcher(`/api/coding/plugin-marketplace/${segment}/${encodeURIComponent(pluginId(id))}`, { method, body: '{}' }));
}
export async function installBetaMarketplacePlugin(id: string, fetcher = defaultFetch) {
return parseMarketplaceInstallation(await fetcher(
`/api/coding/plugin-marketplace/install/${encodeURIComponent(pluginId(id))}/beta`,
{ method: 'POST', body: '{}' },
));
}
export async function installMarketplacePlugin(id: string, fetcher = defaultFetch) {
return installationMutation('POST', 'install', id, fetcher);
}