From eee13c54c5c0272d4777a1aed353142de99f3f7d Mon Sep 17 00:00:00 2001 From: Julio Zynger Date: Mon, 3 Jan 2022 15:33:12 +0100 Subject: [PATCH] Throw errors when response is not ok Signed-off-by: Julio Zynger --- plugins/gocd/package.json | 1 + plugins/gocd/src/api/gocdApi.client.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/plugins/gocd/package.json b/plugins/gocd/package.json index aac6d3d297..0af395637b 100644 --- a/plugins/gocd/package.json +++ b/plugins/gocd/package.json @@ -31,6 +31,7 @@ "@backstage/catalog-model": "^0.9.1", "@backstage/core-components": "^0.8.2", "@backstage/core-plugin-api": "^0.4.0", + "@backstage/errors": "^0.1.4", "@backstage/plugin-catalog-react": "^0.6.0", "@backstage/theme": "^0.2.14", "@material-ui/core": "^4.12.2", diff --git a/plugins/gocd/src/api/gocdApi.client.ts b/plugins/gocd/src/api/gocdApi.client.ts index d74cf9e055..1f4955a80d 100644 --- a/plugins/gocd/src/api/gocdApi.client.ts +++ b/plugins/gocd/src/api/gocdApi.client.ts @@ -16,6 +16,7 @@ import { GoCdApi } from './gocdApi'; import { GoCdApiError, PipelineHistory } from './gocdApi.model'; import { DiscoveryApi } from '@backstage/core-plugin-api'; +import { ResponseError } from '@backstage/errors'; export class GoCdClientApi implements GoCdApi { constructor(private readonly discoveryApi: DiscoveryApi) {} @@ -33,6 +34,10 @@ export class GoCdClientApi implements GoCdApi { }, ); + if (!pipelineHistoryResponse.ok) { + throw await ResponseError.fromResponse(pipelineHistoryResponse); + } + return await pipelineHistoryResponse.json(); } }