Skip to content

Commit

Permalink
Merge 0993a5d into cc85156
Browse files Browse the repository at this point in the history
  • Loading branch information
terales committed Dec 29, 2017
2 parents cc85156 + 0993a5d commit feab3b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/middleware/getImageUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const safeSet = require('lodash.set')
const sources = require(path.join(__dirname, '..', 'sources', 'index'))

module.exports = function getImageUrl (req, res, next) {
Promise.resolve(sources[req.params.source](req.params.user))
const source = sources[req.params.source]

if (!source) { throw new Error('404') }

Promise.resolve(source(req.params.user))
.then(url => {
const image = request(url)
image.on('response', response => {
Expand Down
12 changes: 12 additions & 0 deletions tests/send404onNonExistingSource.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const test = require('ava')
const supertest = require('supertest')

const app = require('./../src/app')

test('Should send 404 on non existent source wothout invoking next error handlers', async t => {
const res = await supertest(app)
.get('/non-existent-source/terales')

t.is(res.statusCode, 404)
t.deepEqual(res.body, {})
})

0 comments on commit feab3b5

Please sign in to comment.