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) {
log.audit({event: "flow.add",id:id},req);
res.json({id:id});
}).otherwise(function(err) {
}).catch(function(err) {
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()});
})
@ -53,7 +53,7 @@ module.exports = {
redNodes.updateFlow(id,flow).then(function() {
log.audit({event: "flow.update",id:id},req);
res.json({id:id});
}).otherwise(function(err) {
}).catch(function(err) {
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()});
})

View File

@ -54,7 +54,7 @@ module.exports = {
} else {
res.json({rev:flowId});
}
}).otherwise(function(err) {
}).catch(function(err) {
log.warn(log._("api.flows.error-reload",{message:err.message}));
log.warn(err.stack);
res.status(500).json({error:"unexpected_error", message:err.message});
@ -77,7 +77,7 @@ module.exports = {
} else if (version === "v2") {
res.json({rev:flowId});
}
}).otherwise(function(err) {
}).catch(function(err) {
log.warn(log._("api.flows.error-save",{message:err.message}));
log.warn(err.stack);
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);
res.json(info);
}
}).otherwise(function(err) {
}).catch(function(err) {
if (err.code === 404) {
log.audit({event: "nodes.install",module:node.module,version:node.version,error:"not_found"},req);
res.status(404).end();
@ -117,7 +117,7 @@ module.exports = {
events.emit("runtime-event",{id:"node/removed",retain:false,payload:list});
log.audit({event: "nodes.remove",module:mod},req);
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);
res.status(400).json({error:err.code||"unexpected_error", message:err.toString()});
});

View File

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