mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Ensure main handler ends
This commit is contained in:
parent
199d657097
commit
273626a799
@ -20,13 +20,15 @@ export class ExpressHttpServer {
|
||||
methods: [ 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE' ],
|
||||
}));
|
||||
|
||||
app.use(async(request, response): Promise<void> => {
|
||||
app.use(async(request, response, done): Promise<void> => {
|
||||
try {
|
||||
await this.handler.handleSafe({ request, response });
|
||||
} catch (error) {
|
||||
const errMsg = `${error.name}: ${error.message}\n${error.stack}`;
|
||||
process.stderr.write(errMsg);
|
||||
response.status(500).contentType('text/plain').send(errMsg);
|
||||
} finally {
|
||||
done();
|
||||
}
|
||||
});
|
||||
return app.listen(port);
|
||||
|
@ -77,6 +77,13 @@ describe('ExpressHttpServer', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a 404 when the handler does not do anything.', async(): Promise<void> => {
|
||||
handler.handle = async(input): Promise<void> => {
|
||||
expect(input).toBeDefined();
|
||||
};
|
||||
await request(server).get('/').expect(404);
|
||||
});
|
||||
|
||||
it('catches errors thrown by its handler.', async(): Promise<void> => {
|
||||
handler.handle = async(): Promise<void> => {
|
||||
throw new Error('dummyError');
|
||||
|
Loading…
x
Reference in New Issue
Block a user