Throw errors when response is not ok

Signed-off-by: Julio Zynger <julio.zynger@soundcloud.com>
This commit is contained in:
Julio Zynger
2022-01-03 15:33:12 +01:00
parent 8ca42b7b49
commit eee13c54c5
2 changed files with 6 additions and 0 deletions
+1
View File
@@ -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",
+5
View File
@@ -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();
}
}