fix: close marketplace client review findings
This commit is contained in:
@@ -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 } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user