Commit 974fcc3f0320010681d77a977e54f09e3063e400
1 parent
73b2d7d6
Exists in
master
and in
4 other branches
Translate api error handling
Showing
4 changed files
with
15 additions
and
21 deletions
Show diff stats
translate-api/app.js
translate-api/controllers/translate.js
... | ... | @@ -9,28 +9,23 @@ |
9 | 9 | * Required libs. |
10 | 10 | */ |
11 | 11 | var shortid = require('shortid') |
12 | - , amqp = require('../helpers/amqpManager'); | |
12 | + , amqp = require('../helpers/amqpManager') | |
13 | + , error = require('../helpers/error'); | |
13 | 14 | |
14 | 15 | exports.translate = function(req, res) { |
15 | 16 | if (!req.body.text) |
16 | - return console.log('Text key is missing'); | |
17 | + return error.badRequest('The text key is missing.', next); | |
17 | 18 | |
18 | 19 | var id = shortid.generate(); |
19 | 20 | var text = req.body.text; |
20 | 21 | |
21 | - amqp.sendToQueue(text, id,'texts', false, res); | |
22 | - amqp.sendToQueue(text, id,'logs', true, res); | |
23 | - amqp.receiveFromQueue(id, 'translations', false, res); | |
24 | -}; | |
25 | - | |
26 | -exports.urltranslate = function(req, res) { | |
27 | - if (!req.body.text) | |
28 | - return console.log('Text key missing'); | |
29 | - | |
30 | - var id = shortid.generate(); | |
31 | - var text = req.param('text').toString('utf8'); | |
32 | - | |
33 | - amqp.sendToQueue(text, id, 'texts', false, res); | |
34 | - amqp.sendToQueue(text, id, 'logs', true, res); | |
35 | - amqp.receiveFromQueue(id, 'translations', false, res); | |
22 | + amqp.sendToQueue(text, id,'texts', false, res, function(err) { | |
23 | + if (err) | |
24 | + return error.internalError('An internal communication error has occurred.', next); | |
25 | + amqp.receiveFromQueue(id, 'translations', false, res, function(err, message) { | |
26 | + if (err) | |
27 | + return error.internalError('An internal communication error has occurred.', next); | |
28 | + res.status(200).send(message); | |
29 | + }); | |
30 | + }); | |
36 | 31 | }; | ... | ... |
translate-api/controllers/video.js
... | ... | @@ -28,7 +28,7 @@ exports.create = function(req, res, next) { |
28 | 28 | video.save(function(err) { |
29 | 29 | if (err) |
30 | 30 | return error.internalError('A database error has occurred.', next); |
31 | - res.json({ id: video._id }); | |
31 | + res.status(200).json({ id: video._id }); | |
32 | 32 | resolve(gloss); |
33 | 33 | }); |
34 | 34 | }) |
... | ... | @@ -69,6 +69,6 @@ exports.status = function(req, res, next) { |
69 | 69 | if (err) |
70 | 70 | return error.notFound('Can\'t find any content.', next); |
71 | 71 | else |
72 | - res.json( { 'status': video.status, 'file': video.file, 'size': video.size } ); | |
72 | + res.status(200).json({ 'status': video.status, 'file': video.file, 'size': video.size }); | |
73 | 73 | }); |
74 | 74 | }; | ... | ... |
translate-api/routes/translate.js