diff --git a/translate-api/app.js b/translate-api/app.js index 849f357..fbbcbae 100755 --- a/translate-api/app.js +++ b/translate-api/app.js @@ -55,7 +55,7 @@ app.use(function(err, req, res, next) { if (app.get('env') !== 'development') delete err.stack res.status(err.status).json({ - error: { + 'error': { 'message': err.message, 'status': err.status, 'stack': err.stack diff --git a/translate-api/controllers/translate.js b/translate-api/controllers/translate.js index 8813709..5b2ce48 100644 --- a/translate-api/controllers/translate.js +++ b/translate-api/controllers/translate.js @@ -9,28 +9,23 @@ * Required libs. */ var shortid = require('shortid') - , amqp = require('../helpers/amqpManager'); + , amqp = require('../helpers/amqpManager') + , error = require('../helpers/error'); exports.translate = function(req, res) { if (!req.body.text) - return console.log('Text key is missing'); + return error.badRequest('The text key is missing.', next); var id = shortid.generate(); var text = req.body.text; - amqp.sendToQueue(text, id,'texts', false, res); - amqp.sendToQueue(text, id,'logs', true, res); - amqp.receiveFromQueue(id, 'translations', false, res); -}; - -exports.urltranslate = function(req, res) { - if (!req.body.text) - return console.log('Text key missing'); - - var id = shortid.generate(); - var text = req.param('text').toString('utf8'); - - amqp.sendToQueue(text, id, 'texts', false, res); - amqp.sendToQueue(text, id, 'logs', true, res); - amqp.receiveFromQueue(id, 'translations', false, res); + amqp.sendToQueue(text, id,'texts', false, res, function(err) { + if (err) + return error.internalError('An internal communication error has occurred.', next); + amqp.receiveFromQueue(id, 'translations', false, res, function(err, message) { + if (err) + return error.internalError('An internal communication error has occurred.', next); + res.status(200).send(message); + }); + }); }; diff --git a/translate-api/controllers/video.js b/translate-api/controllers/video.js index 44536bf..2d5a4db 100644 --- a/translate-api/controllers/video.js +++ b/translate-api/controllers/video.js @@ -28,7 +28,7 @@ exports.create = function(req, res, next) { video.save(function(err) { if (err) return error.internalError('A database error has occurred.', next); - res.json({ id: video._id }); + res.status(200).json({ id: video._id }); resolve(gloss); }); }) @@ -69,6 +69,6 @@ exports.status = function(req, res, next) { if (err) return error.notFound('Can\'t find any content.', next); else - res.json( { 'status': video.status, 'file': video.file, 'size': video.size } ); + res.status(200).json({ 'status': video.status, 'file': video.file, 'size': video.size }); }); }; diff --git a/translate-api/routes/translate.js b/translate-api/routes/translate.js index 01086a5..246cf40 100644 --- a/translate-api/routes/translate.js +++ b/translate-api/routes/translate.js @@ -11,7 +11,6 @@ var express = require('express') * Routes to process text and return gloss. */ router - .get('/', translateController.urltranslate) .post('/', translateController.translate) module.exports = router; -- libgit2 0.21.2