API-16: Content-Type header required (#13)
All checks were successful
Jenkins Production Deployment
All checks were successful
Jenkins Production Deployment
- Sending proper error message to the client when the content-type header is missing Co-authored-by: Patrick Müller <patrick@mueller-patrick.tech> Reviewed-on: #13 Co-authored-by: Patrick Müller <patrick@plutodev.de> Co-committed-by: Patrick Müller <patrick@plutodev.de>
This commit is contained in:
parent
738004c7fe
commit
a64a881598
|
@ -17,6 +17,15 @@ loginRouter.post('/:isDevCall', async (req: Request, res: Response) => {
|
||||||
let password: string = '';
|
let password: string = '';
|
||||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||||
|
|
||||||
|
// Send error when content-type header is missing
|
||||||
|
if (!req.headers['content-type']) {
|
||||||
|
res.status(400).send({
|
||||||
|
'status': 'MISSING_CONTENT_TYPE',
|
||||||
|
'message': 'Please set the content-type header field'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// API accepts both JSON in body and HTTP parameters
|
// API accepts both JSON in body and HTTP parameters
|
||||||
if (req.headers['content-type'] === 'application/json') {
|
if (req.headers['content-type'] === 'application/json') {
|
||||||
username = req.body.username;
|
username = req.body.username;
|
||||||
|
|
|
@ -19,6 +19,15 @@ registerRouter.post('/:isDevCall', async (req: Request, res: Response) => {
|
||||||
let password: string = '';
|
let password: string = '';
|
||||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||||
|
|
||||||
|
// Send error when content-type header is missing
|
||||||
|
if (!req.headers['content-type']) {
|
||||||
|
res.status(400).send({
|
||||||
|
'status': 'MISSING_CONTENT_TYPE',
|
||||||
|
'message': 'Please set the content-type header field'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// API accepts both JSON in body and HTTP parameters
|
// API accepts both JSON in body and HTTP parameters
|
||||||
if (req.headers['content-type'] === 'application/json') {
|
if (req.headers['content-type'] === 'application/json') {
|
||||||
username = req.body.username;
|
username = req.body.username;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user