Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Commit

Permalink
Fix thrown exception on unknown URL for screenshots (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelli committed Sep 11, 2017
1 parent 83b1f76 commit 3bd4977
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ app.get('/render/:url(*)', async(request, response) => {
track('render', now() - start);
} catch (err) {
response.status(400).send('Cannot render requested URL');
console.error('Cannot render requested URL');
console.error(err);
}
});
Expand All @@ -121,7 +122,7 @@ app.get('/screenshot/:url(*)', async(request, response) => {

try {
const start = now();
const result = await renderer.captureScreenshot(request.params.url, request.query, config).catch((err) => console.error(err));
const result = await renderer.captureScreenshot(request.params.url, request.query, config);
const img = new Buffer(result, 'base64');
response.set({
'Content-Type': 'image/jpeg',
Expand All @@ -131,6 +132,7 @@ app.get('/screenshot/:url(*)', async(request, response) => {
track('screenshot', now() - start);
} catch (err) {
response.status(400).send('Cannot render requested URL');
console.error('Cannot render requested URL');
console.error(err);
}
});
Expand Down
6 changes: 6 additions & 0 deletions test/app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,9 @@ test('whitelist ensures other urls do not get rendered', async(t) => {
res = await server.get(`/render/http://anotherDomain.com`);
t.is(res.status, 403);
});

test('unknown url fails safely on screenshot', async(t) => {
const server = await createServer();
const res = await server.get(`/render/http://unknown.blah.com`);
t.is(res.status, 400);
});

0 comments on commit 3bd4977

Please sign in to comment.