|
|
@ -216,6 +216,46 @@ test('send(200, <Stream>) with error on same tick', async t => { |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
test('custom error', async t => { |
|
|
|
const fn = () => { |
|
|
|
sleep(50) |
|
|
|
throw new Error('500 from test (expected)') |
|
|
|
} |
|
|
|
|
|
|
|
const handleErrors = fn => (req, res) => { |
|
|
|
try { |
|
|
|
return fn(req, res) |
|
|
|
} catch (err) { |
|
|
|
send(res, 200, 'My custom error!') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const url = await listen(handleErrors(fn)) |
|
|
|
const res = await request(url) |
|
|
|
|
|
|
|
t.deepEqual(res, 'My custom error!') |
|
|
|
}) |
|
|
|
|
|
|
|
test('custom async error', async t => { |
|
|
|
const fn = async () => { |
|
|
|
sleep(50) |
|
|
|
throw new Error('500 from test (expected)') |
|
|
|
} |
|
|
|
|
|
|
|
const handleErrors = fn => async (req, res) => { |
|
|
|
try { |
|
|
|
return await fn(req, res) |
|
|
|
} catch (err) { |
|
|
|
send(res, 200, 'My custom error!') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const url = await listen(handleErrors(fn)) |
|
|
|
const res = await request(url) |
|
|
|
|
|
|
|
t.deepEqual(res, 'My custom error!') |
|
|
|
}) |
|
|
|
|
|
|
|
test('json parse error', async t => { |
|
|
|
const fn = async (req, res) => { |
|
|
|
const body = await json(req) |
|
|
|