1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Replace when.otherwise() with Promise.catch()

Fixes #1584
This commit is contained in:
Nick O'Leary 2018-01-29 09:50:41 +00:00
parent 1d4a435f20
commit 519edce0ed
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
6 changed files with 12 additions and 12 deletions

View File

@ -40,7 +40,7 @@ module.exports = {
redNodes.addFlow(flow).then(function(id) { redNodes.addFlow(flow).then(function(id) {
log.audit({event: "flow.add",id:id},req); log.audit({event: "flow.add",id:id},req);
res.json({id:id}); res.json({id:id});
}).otherwise(function(err) { }).catch(function(err) {
log.audit({event: "flow.add",error:err.code||"unexpected_error",message:err.toString()},req); log.audit({event: "flow.add",error:err.code||"unexpected_error",message:err.toString()},req);
res.status(400).json({error:err.code||"unexpected_error", message:err.toString()}); res.status(400).json({error:err.code||"unexpected_error", message:err.toString()});
}) })
@ -53,7 +53,7 @@ module.exports = {
redNodes.updateFlow(id,flow).then(function() { redNodes.updateFlow(id,flow).then(function() {
log.audit({event: "flow.update",id:id},req); log.audit({event: "flow.update",id:id},req);
res.json({id:id}); res.json({id:id});
}).otherwise(function(err) { }).catch(function(err) {
log.audit({event: "flow.update",error:err.code||"unexpected_error",message:err.toString()},req); log.audit({event: "flow.update",error:err.code||"unexpected_error",message:err.toString()},req);
res.status(400).json({error:err.code||"unexpected_error", message:err.toString()}); res.status(400).json({error:err.code||"unexpected_error", message:err.toString()});
}) })

View File

@ -54,7 +54,7 @@ module.exports = {
} else { } else {
res.json({rev:flowId}); res.json({rev:flowId});
} }
}).otherwise(function(err) { }).catch(function(err) {
log.warn(log._("api.flows.error-reload",{message:err.message})); log.warn(log._("api.flows.error-reload",{message:err.message}));
log.warn(err.stack); log.warn(err.stack);
res.status(500).json({error:"unexpected_error", message:err.message}); res.status(500).json({error:"unexpected_error", message:err.message});
@ -77,7 +77,7 @@ module.exports = {
} else if (version === "v2") { } else if (version === "v2") {
res.json({rev:flowId}); res.json({rev:flowId});
} }
}).otherwise(function(err) { }).catch(function(err) {
log.warn(log._("api.flows.error-save",{message:err.message})); log.warn(log._("api.flows.error-save",{message:err.message}));
log.warn(err.stack); log.warn(err.stack);
res.status(500).json({error:"unexpected_error", message:err.message}); res.status(500).json({error:"unexpected_error", message:err.message});

View File

@ -81,7 +81,7 @@ module.exports = {
log.audit({event: "nodes.install",module:node.module,version:node.version},req); log.audit({event: "nodes.install",module:node.module,version:node.version},req);
res.json(info); res.json(info);
} }
}).otherwise(function(err) { }).catch(function(err) {
if (err.code === 404) { if (err.code === 404) {
log.audit({event: "nodes.install",module:node.module,version:node.version,error:"not_found"},req); log.audit({event: "nodes.install",module:node.module,version:node.version,error:"not_found"},req);
res.status(404).end(); res.status(404).end();
@ -117,7 +117,7 @@ module.exports = {
events.emit("runtime-event",{id:"node/removed",retain:false,payload:list}); events.emit("runtime-event",{id:"node/removed",retain:false,payload:list});
log.audit({event: "nodes.remove",module:mod},req); log.audit({event: "nodes.remove",module:mod},req);
res.status(204).end(); res.status(204).end();
}).otherwise(function(err) { }).catch(function(err) {
log.audit({event: "nodes.remove",module:mod,error:err.code||"unexpected_error",message:err.toString()},req); log.audit({event: "nodes.remove",module:mod,error:err.code||"unexpected_error",message:err.toString()},req);
res.status(400).json({error:err.code||"unexpected_error", message:err.toString()}); res.status(400).json({error:err.code||"unexpected_error", message:err.toString()});
}); });

View File

@ -36,7 +36,7 @@ function createLibrary(type) {
} else { } else {
res.json(result); res.json(result);
} }
}).otherwise(function(err) { }).catch(function(err) {
if (err) { if (err) {
log.warn(log._("api.library.error-load-entry",{path:path,message:err.toString()})); log.warn(log._("api.library.error-load-entry",{path:path,message:err.toString()}));
if (err.code === 'forbidden') { if (err.code === 'forbidden') {
@ -59,7 +59,7 @@ function createLibrary(type) {
storage.saveLibraryEntry(type,path,meta,text).then(function() { storage.saveLibraryEntry(type,path,meta,text).then(function() {
log.audit({event: "library.set",type:type},req); log.audit({event: "library.set",type:type},req);
res.status(204).end(); res.status(204).end();
}).otherwise(function(err) { }).catch(function(err) {
log.warn(log._("api.library.error-save-entry",{path:path,message:err.toString()})); log.warn(log._("api.library.error-save-entry",{path:path,message:err.toString()}));
if (err.code === 'forbidden') { if (err.code === 'forbidden') {
log.audit({event: "library.set",type:type,error:"forbidden"},req); log.audit({event: "library.set",type:type,error:"forbidden"},req);
@ -123,7 +123,7 @@ module.exports = {
log.audit({event: "library.get",type:"flow",path:req.params[0]},req); log.audit({event: "library.get",type:"flow",path:req.params[0]},req);
res.set('Content-Type', 'application/json'); res.set('Content-Type', 'application/json');
res.send(data); res.send(data);
}).otherwise(function(err) { }).catch(function(err) {
if (err) { if (err) {
log.warn(log._("api.library.error-load-flow",{path:req.params[0],message:err.toString()})); log.warn(log._("api.library.error-load-flow",{path:req.params[0],message:err.toString()}));
if (err.code === 'forbidden') { if (err.code === 'forbidden') {
@ -147,7 +147,7 @@ module.exports = {
storage.saveFlow(req.params[0],flow).then(function() { storage.saveFlow(req.params[0],flow).then(function() {
log.audit({event: "library.set",type:"flow",path:req.params[0]},req); log.audit({event: "library.set",type:"flow",path:req.params[0]},req);
res.status(204).end(); res.status(204).end();
}).otherwise(function(err) { }).catch(function(err) {
log.warn(log._("api.library.error-save-flow",{path:req.params[0],message:err.toString()})); log.warn(log._("api.library.error-save-flow",{path:req.params[0],message:err.toString()}));
if (err.code === 'forbidden') { if (err.code === 'forbidden') {
log.audit({event: "library.set",type:"flow",path:req.params[0],error:"forbidden"},req); log.audit({event: "library.set",type:"flow",path:req.params[0],error:"forbidden"},req);

View File

@ -90,7 +90,7 @@ module.exports = {
settings.setUserSettings(username, currentSettings).then(function() { settings.setUserSettings(username, currentSettings).then(function() {
log.audit({event: "settings.update",username:username},req); log.audit({event: "settings.update",username:username},req);
res.status(204).end(); res.status(204).end();
}).otherwise(function(err) { }).catch(function(err) {
log.audit({event: "settings.update",username:username,error:err.code||"unexpected_error",message:err.toString()},req); log.audit({event: "settings.update",username:username,error:err.code||"unexpected_error",message:err.toString()},req);
res.status(400).json({error:err.code||"unexpected_error", message:err.toString()}); res.status(400).json({error:err.code||"unexpected_error", message:err.toString()});
}); });

View File

@ -301,7 +301,7 @@ function loadNodeSet(node) {
node.enabled = true; node.enabled = true;
node.loaded = true; node.loaded = true;
return node; return node;
}).otherwise(function(err) { }).catch(function(err) {
node.err = err; node.err = err;
return node; return node;
}); });