Migrate all scaffolder API calls to ResponseError

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-05-06 18:22:26 +02:00
parent 81ef1d57bf
commit 15e248a107
+7 -6
View File
@@ -129,9 +129,7 @@ export class ScaffolderClient implements ScaffolderApi {
});
if (!response.ok) {
throw new Error(
`Failed to fetch template parameter schema, ${await response.text()}`,
);
throw ResponseError.fromResponse(response);
}
const schema: TemplateParameterSchema = await response.json();
@@ -161,9 +159,7 @@ export class ScaffolderClient implements ScaffolderApi {
});
if (response.status !== 201) {
const status = `${response.status} ${response.statusText}`;
const body = await response.text();
throw new Error(`Backend request failed, ${status} ${body.trim()}`);
throw ResponseError.fromResponse(response);
}
const { id } = (await response.json()) as { id: string };
@@ -241,6 +237,11 @@ export class ScaffolderClient implements ScaffolderApi {
async listActions(): Promise<ListActionsResponse> {
const baseUrl = await this.discoveryApi.getBaseUrl('scaffolder');
const response = await fetch(`${baseUrl}/v2/actions`);
if (!response.ok) {
throw ResponseError.fromResponse(response);
}
return await response.json();
}
}