Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('compute status pages from expression', async (assert) => {
class AppHandler extends HttpExceptionHandler {
protected statusPages = {
'500..509': '500.edge',
}
protected context () {
return { username: 'virk' }
}
}
const appHandler = new AppHandler(new FakeLogger(loggerConfig))
assert.deepEqual(appHandler.expandedStatusPages, {
500: '500.edge',
501: '500.edge',
502: '500.edge',
503: '500.edge',
504: '500.edge',
505: '500.edge',
506: '500.edge',
507: '500.edge',
508: '500.edge',
509: '500.edge',
})
})
test('report error with custom context', (assert) => {
class AppHandler extends HttpExceptionHandler {
protected context () {
return { username: 'virk' }
}
}
const logger = new FakeLogger(loggerConfig)
const handler = new AppHandler(logger)
const ctx = HttpContext.create('/', {}, logger, new Profiler({}).create(''), encryption)
handler.report(new Exception('bad request', 500, 'E_BAD_REQUEST'), ctx)
assert.deepEqual(logger.logs.map(({ level, msg, username }) => {
return { level, msg, username}
}), [
{
level: 50,
username: 'virk',
msg: 'E_BAD_REQUEST: bad request',
},
])
})
test('handle exception by returning html', async (assert) => {
class AppHandler extends HttpExceptionHandler {
protected context () {
return { username: 'virk' }
}
}
class InvalidAuth extends Exception {
}
const logger = new FakeLogger(loggerConfig)
const handler = new AppHandler(logger)
const ctx = HttpContext.create('/', {}, logger, new Profiler({}).create(''), encryption)
ctx.request.request.headers = { accept: 'text/html' }
await handler.handle(new InvalidAuth('bad request'), ctx)
assert.deepEqual(ctx.response.lazyBody!.args, ['<h1> bad request </h1>', false])
})
export function getLogger () {
return new FakeLogger({
enabled: true,
name: 'lucid',
level: 'info',
})
}