From 8a63218bcb0ae31a7ba80a91af2fcd3647819dc2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Apr 2018 23:55:06 +0200 Subject: [PATCH] File Module with Error Handling --- .vs/AAWeb/v15/.suo | Bin 66048 -> 66048 bytes Files/File.js | 86 +++++++++++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 35 deletions(-) diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index 4e83290e80c73f37c0a51057d36a31cd975a6ec1..7b7821b29a2b5dc765532310c3a5ad7eb5aa20b3 100644 GIT binary patch delta 340 zcmZo@VQFY#*^tA;I>A<1Lv!7hjfFu52+PTsR-CQD36X6~kKLCljI_VP^H!nygt8aqZoUAR)E1HnLc z%I5vM9GNHWWo2P^%gmXyZ{wsbER51XK{v+9dP@y9>zs>a+T44nl6`WI=TDh6`PB5&+>_w)GbT^mn>9Iqi#|~NCtO`ru-asU zDOQtx*BNg9G9#C1^N*!Qj7*FSlP^xuLlvC-Z$2L*+>p%+7eq1gGB7d%?FNBN2Ne5( z((#Ow7c660w1jK2;uO!#z8khPPA;6$yt!_}4HiKUh$b+}3M8c`?^!ctGs~tRW~@?k zCkL!uH(6kh=wy~H*_$dgptKLF*#$=8K%jJ%XGlfEdT!-x@_*fP;3YQaxIJd diff --git a/Files/File.js b/Files/File.js index c15a85191..ed3aa34a7 100644 --- a/Files/File.js +++ b/Files/File.js @@ -3,6 +3,7 @@ function newFile() { const MODULE_NAME = "File"; const INFO_LOG = false; + const ERROR_LOG = true; const logger = newDebugLog(); logger.fileName = MODULE_NAME; @@ -18,63 +19,78 @@ function newFile() { function initialize(pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } + try { - let exchange = ecosystem.getExchange(pProduct, pExchange); + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } - if (pExchange !== undefined && exchange === undefined) { // We support no exchange as a parameter, but if provided, then it must be at the list of exchanges of that product. + let exchange = ecosystem.getExchange(pProduct, pExchange); - throw "Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange; + if (pExchange !== undefined && exchange === undefined) { // We support no exchange as a parameter, but if provided, then it must be at the list of exchanges of that product. - } + throw "Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange; - fileCloud = newFileCloud(); - fileCloud.initialize(pBot); + } - /* Now we will get the file */ + fileCloud = newFileCloud(); + fileCloud.initialize(pBot); - fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, undefined, onFileReceived); + /* Now we will get the file */ - function onFileReceived(err, pFile) { + fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, undefined, onFileReceived); - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Entering function."); } + function onFileReceived(err, pFile) { - switch (err.result) { - case GLOBAL.DEFAULT_OK_RESPONSE.result: { + try { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received OK Response."); } - break; - } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Entering function."); } - case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received FAIL Response."); } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); - return; - } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received OK Response."); } + break; + } - case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received CUSTOM FAIL Response."); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> err.message = " + err.message); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received FAIL Response."); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } - callBackFunction(err); - return; - } + case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { - default: { + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received CUSTOM FAIL Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> err.message = " + err.message); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received Unexpected Response."); } - callBackFunction(err); - return; + callBackFunction(err); + return; + } + + default: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received Unexpected Response."); } + callBackFunction(err); + return; + } + } + + file = pFile; + + callBackFunction(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileReceived -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); } } - file = pFile; - - callBackFunction(); + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); } }