simplify response

This commit is contained in:
Simon Martín 2018-05-25 17:57:40 +02:00
parent 1fa5afd759
commit b31984cbc6

View File

@ -34,7 +34,6 @@ CopyController.prototype.route = function (app) {
timeoutLimitsMiddleware(this.metadataBackend),
validateCopyQuery(),
handleCopyFrom(this.logger),
responseCopyFrom(),
errorHandler(),
errorMiddleware()
];
@ -79,7 +78,6 @@ function handleCopyTo (logger) {
logger.info(metrics);
// this is a especial endpoint
// the data from postgres is streamed to response directly
// next() no needed
}
);
};
@ -97,6 +95,10 @@ function handleCopyFrom (logger) {
return next(err);
}
if (!result || !result.total_rows) {
return next(new Error("No rows copied"));
}
logger.info(metrics);
// TODO: remove when data-ingestion log works
@ -105,24 +107,12 @@ function handleCopyFrom (logger) {
res.header('X-SQLAPI-Profiler', req.profiler.toJSONString());
}
res.body = result;
next();
res.send(result);
}
)
};
}
function responseCopyFrom () {
return function responseCopyFromMiddleware (req, res, next) {
if (!res.body || !res.body.total_rows) {
return next(new Error("No rows copied"));
}
res.send(res.body);
};
}
function validateCopyQuery () {
return function validateCopyQueryMiddleware (req, res, next) {
const sql = req.query.q;