Handle api exceptions in bundlephobia

pull/282/head
Amio 2019-06-04 09:12:51 +08:00
rodzic 7eb01c9734
commit 8b14255ac0
1 zmienionych plików z 11 dodań i 1 usunięć

Wyświetl plik

@ -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':