Place send-response-middleware to the very end of middleware stack

This commit is contained in:
Daniel García Aubert 2018-02-23 13:03:56 +01:00
parent 3807d9f94d
commit 47b54612c7

View File

@ -44,6 +44,7 @@ function composeJobMiddlewares (metadataBackend, userDatabaseService, jobService
finishProfilerMiddleware(),
logJobResult(action),
incrementSuccessMetrics(statsdClient),
sendResponse(),
incrementErrorMetrics(statsdClient),
errorMiddleware()
];
@ -63,7 +64,7 @@ function cancelJob (jobService) {
return next(err);
}
res.status(200).send(job.serialize());
res.body = job.serialize();
next();
});
@ -83,7 +84,7 @@ function getJob (jobService) {
return next(err);
}
res.status(200).send(job.serialize());
res.body = job.serialize();
next();
});
@ -115,7 +116,8 @@ function createJob (jobService) {
res.locals.job_id = job.job_id;
res.status(201).send(job.serialize());
res.statusCode = 201;
res.body = job.serialize();
next();
});
@ -129,7 +131,7 @@ function listWorkInProgressJobs (jobService) {
return next(err);
}
res.status(200).send(list);
res.body = list;
next();
});
@ -216,3 +218,9 @@ function incrementErrorMetrics (statsdClient) {
next(err);
};
}
function sendResponse () {
return function sendResponseMiddleware (req, res) {
res.status(res.statusCode || 200).send(res.body);
};
}