From c2cca39c7dc696f564a7c9e86cb197380b2c855c Mon Sep 17 00:00:00 2001 From: Viljami Kuosmanen Date: Sun, 29 Mar 2020 19:35:25 +0200 Subject: [PATCH] openapi: minor improvements --- src/node/handler/APIHandler.js | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index cd3258252..aecc92e13 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -185,37 +185,11 @@ exports.handle = async function(apiVersion, functionName, fields, req, res) fields["padName"] = await padManager.sanitizePadId(fields["padName"]); } - // no need to await - callAPI returns a promise - return callAPI(apiVersion, functionName, fields, req, res); -} - -// calls the api function -async function callAPI(apiVersion, functionName, fields, req, res) -{ // put the function parameters in an array var functionParams = version[apiVersion][functionName].map(function (field) { return fields[field] }); - try { - // call the api function - let data = await api[functionName].apply(this, functionParams); - - if (!data) { - data = null; - } - - res.send({code: 0, message: "ok", data: data}); - } catch (err) { - if (err.name == "apierror") { - // parameters were wrong and the api stopped execution, pass the error - - res.send({code: 1, message: err.message, data: null}); - } else { - // an unknown error happened - - res.send({code: 2, message: "internal error", data: null}); - throw err; - } - } + // call the api function + return api[functionName].apply(this, functionParams); }