Skip to content

Commit 7804b22

Browse files
committed
reject when fetch fails
1 parent b6b89e0 commit 7804b22

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/health.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ export class Health {
3939
const status = response.status;
4040
if (status === 200) {
4141
return true;
42-
} else if (status === 404) {
42+
}
43+
if (status === 404) {
4344
if (path === '/healthz') {
4445
// /livez/readyz return 404 and healthz also returns 404, let's consider it is live
4546
return true;
4647
}
4748
return this.healthz(opts);
48-
} else {
49-
return false;
5049
}
51-
} catch {
5250
return false;
51+
} catch {
52+
throw new Error('Error occurred in health request');
5353
}
5454
}
5555
}

src/health_test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('Health', () => {
124124
scope.done();
125125
});
126126

127-
it('should return false when fetch throws an error', async () => {
127+
it('should throw an error when fetch throws an error', async () => {
128128
const kc = new KubeConfig();
129129
const cluster = {
130130
name: 'foo',
@@ -141,8 +141,7 @@ describe('Health', () => {
141141
scope.get('/livez').replyWithError(new Error('an error'));
142142
const health = new Health(kc);
143143

144-
const r = await health.livez({});
145-
expect(r).to.be.false;
144+
await expect(health.livez({})).to.be.rejectedWith('Error occurred in health request');
146145
scope.done();
147146
});
148147
});

0 commit comments

Comments
 (0)