From b3bb2411866d45a82a804479cc1ec2677d68175a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 6 Mar 2018 20:39:46 +0100 Subject: [PATCH] Error handling major refactoring --- .vs/AAMariam-Trading-Bot/v15/.suo | Bin 19456 -> 27648 bytes Project.njsproj | 3 +-- Trading-Process/This.Bot.js => This.Bot.js | 25 +++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) rename Trading-Process/This.Bot.js => This.Bot.js (92%) diff --git a/.vs/AAMariam-Trading-Bot/v15/.suo b/.vs/AAMariam-Trading-Bot/v15/.suo index f4145eac2e76c556d7f752ed02c64c8c0ba08381..f4eb38ccd77f4b8fad5eb02ff59466c3ef7407f0 100644 GIT binary patch delta 1216 zcmc(eO-vI}5XawaOWV*cwonT;K!9Sbs7*gWT0mU8YeD=1ib!Ij)j$BFRHf~qG_uB{ z2chG^7*FWY#Ket>95lp(S3*pTi5Jes#7mo?Cf0eiNTVK%2YtzJU+2Fwv$Oy1Q}2TM z78bk>0xK;mV|w}t#MeThz*U{LsE@;9Ovwtzz=F*?n#7KjXYT21aL`@ViD@AX)0h`- z3Nam~bw^OH_CXZ$y4#|w)Tfp97V7g3s=UKf=Ts_o|E}1W=7q*pF;FUOr`@lunaqO3 z=izjb)J^md2Z&zcAR!Tlh%mwP6xt6H5u%U4dUF%rskGLOP;iPEB~BA#M2x_3b5BL_ zDT_mAvX%r4W70AYLzt)Qpq3OT;eQTcjheV;^kxOTQQOKVvPHqfW4^ei<*HAD2sTPH zl&1zUX+I$XPt%p@TFyQQ7Lk;uay8*l4HYse0sK_|1wxo_n1`U2Y<%bxuaV3@4vrT; zcDh9mn`M{S%$8y-DVXUR#r04#Focd?P3lew+b7t0N}pgE7N9|Dij5xQS@}ACko|Zo zTm?KzW$SZW0~kV-mJ+njE`wm0ncNqSC-A-8t_P-UmiEE`-j^lw)by-}ZhJ1y7Gr#) zT((h=$;|oM$9#-4AxQnNv3do?wp0!saoCPh}@f!YsCN8yQE0aU8JT4Fa@>!R+v zh|T{8SNwY1Xd5)y%S0`)X9P@*E#*M~}Kfwi!Uy1d-6{?AUz)7CD=j*<6=AK)A&&zlD zosk~4|JWEa!RFv+y*Ij&i9JVkj+iJzw$-gA0hzR3Tpu58IR8QtPvf6o9db|ks}#_8wU z!KmCwh*38SPU!jGHN!KnU-OT6f9|xEA7O2<{V~D$%&Vw?%l* z8{Vgc+dj+EY>_RqVH|yy<*;VhGTjQykro{0jJAW5dN{Zu*@x88Sj-<#1IH@{#yT6a zn=}zQrnz?iG++uLu_Ec;y(UQuou(zlPTP?ox)!o>QGI9fhhVW5FeX5tH6Ha?-ryVXs-`U2DCD>1BRUM?V;v-+op@-vJoII)ra|;6IbPm-dcpiUm)baRwexFJ=<$}qA5HOJ8D{bv diff --git a/Project.njsproj b/Project.njsproj index e75e319d8..83de1393a 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -28,7 +28,6 @@ - @@ -41,7 +40,7 @@ - + diff --git a/Trading-Process/This.Bot.js b/This.Bot.js similarity index 92% rename from Trading-Process/This.Bot.js rename to This.Bot.js index f53bddcd0..e2eeda39f 100644 --- a/Trading-Process/This.Bot.js +++ b/This.Bot.js @@ -35,11 +35,11 @@ logger.write("[INFO] initialize -> Entering function 'initialize' "); - callBackFunction(null); + callBackFunction(DEFAULT_OK_RESPONSE); } catch (err) { logger.write("[ERROR] initialize -> onDone -> err = " + err.message); - callBackFunction("Operation Failed"); + callBackFunction(DEFAULT_FAIL_RESPONSE); } } @@ -64,18 +64,19 @@ function onDone(err) { try { - switch (err) { - case null: { - callBackFunction(null); + switch (err.result) { + case DEFAULT_OK_RESPONSE.result: { + callBackFunction(DEFAULT_OK_RESPONSE); + return; } break; - case 'Retry Later': { // Something bad happened, but if we retry in a while it might go through the next time. + case DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. logger.write("[ERROR] start -> onDone -> Retry Later. Requesting Execution Retry."); callBackFunction(err.message); return; } break; - case 'Retry Later': { // This is an unexpected exception that we do not know how to handle. + case DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. logger.write("[ERROR] start -> onDone -> Operation Failed. Aborting the process."); callBackFunction(err.message); return; @@ -85,7 +86,7 @@ } catch (err) { logger.write("[ERROR] start -> onDone -> err = " + err.message); - callBackFunction("Operation Failed"); + callBackFunction(DEFAULT_FAIL_RESPONSE); } } @@ -173,7 +174,7 @@ } } catch (err) { logger.write("[ERROR] start -> businessLogic -> err = " + err.message); - callBack("Operation Failed"); + callBack(DEFAULT_FAIL_RESPONSE); } } @@ -187,7 +188,7 @@ } catch (err) { logger.write("[ERROR] start -> decideAboutBuyPosition -> err = " + err.message); - callBack("Operation Failed"); + callBack(DEFAULT_FAIL_RESPONSE); } } @@ -257,13 +258,13 @@ } catch (err) { logger.write("[ERROR] start -> decideAboutSellPosition -> err = " + err.message); - callBack("Operation Failed"); + callBack(DEFAULT_FAIL_RESPONSE); } } } catch (err) { logger.write("[ERROR] start -> err = " + err.message); - callBackFunction("Operation Failed"); + callBackFunction(DEFAULT_FAIL_RESPONSE); } } };