Skip to content

Commit

Permalink
fix: send http 500 error in case of exception
Browse files Browse the repository at this point in the history
  • Loading branch information
rorlic committed Apr 9, 2024
1 parent 455b5f6 commit 852487a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ server.get('/', async (request, reply) => {
const body = controller.getTestRunsOverview();
return reply.header('content-type', 'text/html').send(body);
} catch (error) {
return reply.send({ msg: 'Cannot display test runs overview\n', error: error });
return reply.status(500).send({ msg: 'Cannot display test runs overview\n', error: error });
}
});

Expand All @@ -147,7 +147,7 @@ server.get('/:id', { schema: { querystring: { limit: { type: 'number' } } } }, a
return reply.status(404).send('');
}
} catch (error) {
return reply.send({ msg: `Cannot display status for test run ${id}\n`, error: error });
return reply.status(500).send({ msg: `Cannot display status for test run ${id}\n`, error: error });
}
});

Expand Down Expand Up @@ -175,7 +175,7 @@ server.delete('/test', { schema: { querystring: { confirm: { type: 'boolean' } }
: reply.status(405).send("No tests cancelled nor deleted.\nHint:pass query parameter '?confirm=true' to actually delete all tests.\n");

} catch (error) {
return reply.send({ msg: 'Cannot delete all tests\n', error: error });
return reply.status(500).send({ msg: 'Cannot delete all tests\n', error: error });
}
});

Expand All @@ -202,7 +202,7 @@ server.delete('/test/:id', { schema: { querystring: { confirm: { type: 'boolean'
: reply.status(404).send(`Test ${id} not found\n`);

} catch (error) {
return reply.send({ msg: `Cannot delete test ${id}\n`, error: error });
return reply.status(500).send({ msg: `Cannot delete test ${id}\n`, error: error });
}
});

Expand Down

0 comments on commit 852487a

Please sign in to comment.