Skip to content
Snippets Groups Projects
Commit 27582319 authored by syuilo's avatar syuilo
Browse files

Catch error

parent 44bb9925
No related branches found
Tags 13.10.3
No related merge requests found
......@@ -2,14 +2,18 @@ import * as Koa from 'koa';
import summaly from 'summaly';
module.exports = async (ctx: Koa.Context) => {
const summary = await summaly(ctx.query.url);
summary.icon = wrap(summary.icon);
summary.thumbnail = wrap(summary.thumbnail);
try {
const summary = await summaly(ctx.query.url);
summary.icon = wrap(summary.icon);
summary.thumbnail = wrap(summary.thumbnail);
// Cache 7days
ctx.set('Cache-Control', 'max-age=604800, immutable');
// Cache 7days
ctx.set('Cache-Control', 'max-age=604800, immutable');
ctx.body = summary;
ctx.body = summary;
} catch (e) {
ctx.status = 500;
}
};
function wrap(url: string): string {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment