Set Proxy via node.js causes unexpected errors in script



  • I am trying to use set proxy via BAS_API call in node with catching error. In result if catch exception and repeat set proxy call with another proxy (all in one node) thread ends with error "Task id not found".

    Trying to debug and short it to such code that setup invalid proxy and try to catch error. As result it causes "TypeError: Result of expression '_PROXY["ip"]' [undefined] is not an object. during execution of action 616813916"but only if this node.js called inside function. If it is called in main thread then no error.

    So far I am not sure if those 2 are linked. But may be I do miss something obvious? Thanks for any help.

    Error appears on next block after node.js block.

    try {
        await BAS_API("var hash = proxy_parse('123.123.123.123:8000')\nif(\"http\" != \"auto\" ){\nhash[\"IsHttp\"] = \"http\" == \"http\"\n}\nvar login = \"\"\nvar password = \"\"\nif(login.length > 0 && password.length > 0 )\n{\nhash[\"name\"] = login\nhash[\"password\"] = password\n}\nif(_get_profile().length > 0)\n{\nif(hash[\"server\"].length == 0)\n{\nnative(\"filesystem\", \"removefile\", _get_profile() + \"/proxy.txt\")\n}else\n{\nvar PortNumber = hash[\"Port\"]\nhash[\"Port\"] = hash[\"Port\"].toString()\nnative(\"filesystem\", \"writefile\", JSON.stringify({path: _get_profile() + \"/proxy.txt\",value: JSON.stringify(hash),base64:false,append:false}))\nhash[\"Port\"] = PortNumber\n}\n}\nset_proxy(hash[\"server\"], hash[\"Port\"], hash[\"IsHttp\"], hash[\"name\"], hash[\"password\"])!\nsleep(1000)!\nset_proxy_extended(true, \"false\" == \"true\", \"true\" == \"true\", \"true\" == \"true\", \"true\" == \"true\", \"database\", \"\", null)!");
        console.log('Set proxy success');
    } catch (e) {
        console.log('Set proxy error: ' + JSON.stringify(e));
    }
    

    UPDATE: If modify code with reset proxy in catch I get "Task id not found" error.

    
    try {
        await BAS_API("var hash = proxy_parse('123.123.123.123:8000')\nif(\"http\" != \"auto\" ){\nhash[\"IsHttp\"] = \"http\" == \"http\"\n}\nvar login = \"\"\nvar password = \"\"\nif(login.length > 0 && password.length > 0 )\n{\nhash[\"name\"] = login\nhash[\"password\"] = password\n}\nif(_get_profile().length > 0)\n{\nif(hash[\"server\"].length == 0)\n{\nnative(\"filesystem\", \"removefile\", _get_profile() + \"/proxy.txt\")\n}else\n{\nvar PortNumber = hash[\"Port\"]\nhash[\"Port\"] = hash[\"Port\"].toString()\nnative(\"filesystem\", \"writefile\", JSON.stringify({path: _get_profile() + \"/proxy.txt\",value: JSON.stringify(hash),base64:false,append:false}))\nhash[\"Port\"] = PortNumber\n}\n}\nset_proxy(hash[\"server\"], hash[\"Port\"], hash[\"IsHttp\"], hash[\"name\"], hash[\"password\"])!\nsleep(1000)!\nset_proxy_extended(true, \"false\" == \"true\", \"true\" == \"true\", \"true\" == \"true\", \"true\" == \"true\", \"database\", \"\", null)!");
        console.log('Set proxy success');
    } catch (e) {
        console.log('Set proxy error: ' + JSON.stringify(e));
        await BAS_API("var hash = proxy_parse(\"\")\nif(\"http\" != \"auto\" ){\nhash[\"IsHttp\"] = \"http\" == \"http\"\n}\nvar login = \"\"\nvar password = \"\"\nif(login.length > 0 && password.length > 0 )\n{\nhash[\"name\"] = login\nhash[\"password\"] = password\n}\nif(_get_profile().length > 0)\n{\nif(hash[\"server\"].length == 0)\n{\nnative(\"filesystem\", \"removefile\", _get_profile() + \"/proxy.txt\")\n}else\n{\nvar PortNumber = hash[\"Port\"]\nhash[\"Port\"] = hash[\"Port\"].toString()\nnative(\"filesystem\", \"writefile\", JSON.stringify({path: _get_profile() + \"/proxy.txt\",value: JSON.stringify(hash),base64:false,append:false}))\nhash[\"Port\"] = PortNumber\n}\n}\nset_proxy(hash[\"server\"], hash[\"Port\"], hash[\"IsHttp\"], hash[\"name\"], hash[\"password\"])!\nsleep(1000)!\nset_proxy_extended(false, \"false\" == \"true\", \"true\" == \"true\", \"true\" == \"true\", \"true\" == \"true\", \"database\", \"\", null)!");
    }
    

Log in to reply