From 8b14255ac0dead28c337376d00d401a5752e4579 Mon Sep 17 00:00:00 2001 From: Amio Date: Tue, 4 Jun 2019 09:12:51 +0800 Subject: [PATCH] Handle api exceptions in bundlephobia --- endpoints/bundlephobia.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/endpoints/bundlephobia.ts b/endpoints/bundlephobia.ts index aa76cfe..9698e51 100644 --- a/endpoints/bundlephobia.ts +++ b/endpoints/bundlephobia.ts @@ -28,7 +28,17 @@ export default badgenServe(handlers) async function handler ({ topic, scope, name }: Args) { const pkg = scope ? `${scope}/${name}` : name const endpoint = `https://bundlephobia.com/api/size?package=${pkg}` - const { size, gzip } = await got(endpoint).then(res => res.body) + const resp = await got(endpoint).then(res => res.body) + + if (!resp) { + return { + subject: 'bundlephobia', + status: 'unknown', + color: 'grey' + } + } + + const { size, gzip } = resp switch (topic) { case 'min':