skydiver / ewelink-api

eWeLink API for JavaScript
https://www.npmjs.com/package/ewelink-api
MIT License
264 stars 108 forks source link

UnhandledPromiseRejectionWarning #131

Closed AgentFire closed 2 years ago

AgentFire commented 3 years ago

The code (from the QuickStart guide -_-):

const ewelink = require('ewelink-api');

(async () => {
    const connection = new ewelink({
        email: 'user',
        password: 'pwd',
        region: 'eu',
    });

    const devices = await connection.getDevices(); // This works!
    console.log(devices.length);

    const device = await connection.getDevice('1000а9с054'); // This doesn't!
    console.log(device);
})();

The error:

(node:10072) UnhandledPromiseRejectionWarning: TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters at new ClientRequest (_http_client.js:151:13) at request (https.js:313:10) at C:\Users\AgentFire\Desktop\ewelink-api\node_modules\node-fetch\lib\index.js:1438:15 at new Promise () at fetch (C:\Users\AgentFire\Desktop\ewelink-api\node_modules\node-fetch\lib\index.js:1407:9) at eWeLink.makeRequest (C:\Users\AgentFire\Desktop\ewelink-api\node_modules\ewelink-api\src\mixins\makeRequest.js:44:27) at eWeLink.getDevice (C:\Users\AgentFire\Desktop\ewelink-api\node_modules\ewelink-api\src\mixins\getDevice.js:18:31) at C:\Users\AgentFire\Desktop\ewelink-api\app.js:13:34 at processTicksAndRejections (internal/process/task_queues.js:93:5) (Use node --trace-warnings ... to show where the warning was created) (node:10072) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:10072) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

P.S. Does your API has actual API documentation? Because all I see over the internet is some stupid NODEJS libraries, and I certainly neither want them or need them. I hoped to wireshark the actual useful info from your node module, and even this failed to execute. Your device works via UDP (or TCP), and I expect you to have the complete documentation for each device. Share me the link?

jumpjack commented 3 years ago

Try including ewelink call into try-catch structure, so you can at least manage the error and study it:

try { const connection = new ewelink({ email: 'user', password: 'pwd', region: 'eu', }); } catch (error) { console.error(error); }

AgentFire commented 2 years ago

Since the HTTP API came to life, there is no more need in this monstrosity.