Fix uncaught error when browsing non-existing repo

This commit is contained in:
Alice Gaudon 2020-11-16 17:19:36 +01:00
parent f703e09604
commit 2df7ec4e20

View File

@ -24,18 +24,22 @@ export default class GiteaRepoLatestReleaseController extends Controller {
data += c; data += c;
}); });
r.on('end', () => { r.on('end', () => {
const assets = JSON.parse(data)[0].assets; try {
const assets = JSON.parse(data)[0].assets;
if (file) { if (file) {
for (const asset of assets) { for (const asset of assets) {
if (asset.name === file) { if (asset.name === file) {
log.debug('Redirect to', asset.browser_download_url); log.debug('Redirect to', asset.browser_download_url);
return res.redirect(302, asset.browser_download_url); return res.redirect(302, asset.browser_download_url);
}
} }
} else {
log.debug('List files');
return res.render('list-files', {assets: assets});
} }
} else { } catch (e) {
log.debug('List files'); return next(e);
return res.render('list-files', {assets: assets});
} }
}); });
}).on('error', err => { }).on('error', err => {