Correct API errors
This commit is contained in:
parent
328841b80c
commit
277d4a51ee
|
@ -60,7 +60,7 @@ var API = module.exports = function API(opts) {
|
|||
|
||||
// error handling
|
||||
this.express.use(function(err, req, res, next) {
|
||||
res.json(500, { error: err.message || "An error occured."})
|
||||
res.status(500).json({ error: err.message || "An error occured."})
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -20,21 +20,21 @@ var load = function load(req, res, next) {
|
|||
if (robot) {
|
||||
req.robot = Cylon.robots[robot];
|
||||
if (!req.robot) {
|
||||
return res.json(404, { error: "No Robot found with the name " + robot });
|
||||
return res.status(404).json({ error: "No Robot found with the name " + robot });
|
||||
}
|
||||
}
|
||||
|
||||
if (device) {
|
||||
req.device = req.robot.devices[device];
|
||||
if (!req.device) {
|
||||
return res.json(404, { error: "No device found with the name " + device });
|
||||
return res.status(404).json({ error: "No device found with the name " + device });
|
||||
}
|
||||
}
|
||||
|
||||
if (connection) {
|
||||
req.connection = req.robot.connections[connection];
|
||||
if (!req.connection) {
|
||||
return res.json(404, { error: "No connection found with the name " + connection });
|
||||
return res.status(404).json({ error: "No connection found with the name " + connection });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ var Connection = module.exports = function Connection(opts) {
|
|||
this.details = {};
|
||||
|
||||
for (var opt in opts) {
|
||||
if (['robot', 'name', 'adaptor'].indexOf(opt) < 0) {
|
||||
if (['robot', 'name', 'adaptor', 'connection'].indexOf(opt) < 0) {
|
||||
this.details[opt] = opts[opt];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ var Device = module.exports = function Device(opts) {
|
|||
this.details = {};
|
||||
|
||||
for (var opt in opts) {
|
||||
if (['robot', 'name', 'connection', 'driver'].indexOf(opt) < 0) {
|
||||
if (['robot', 'name', 'connection', 'driver', 'device', 'adaptor'].indexOf(opt) < 0) {
|
||||
this.details[opt] = opts[opt];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue