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