Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(node:83873) UnhandledPromiseRejectionWarning: nope! #7

Open
Eisteed opened this issue Jul 8, 2022 · 4 comments
Open

(node:83873) UnhandledPromiseRejectionWarning: nope! #7

Eisteed opened this issue Jul 8, 2022 · 4 comments

Comments

@Eisteed
Copy link

Eisteed commented Jul 8, 2022

Hello, I'm trying out your script on my server running nodejs 16.15.0
Installed with
npm install nextcloud-talk-bot

Tried the the "usage" example on your readme (added debug:true) but this result in this error :

node bot.js
* autojoin all known channels
@ [self@undefined] adding callback
+ [self@channelid] joined
@ [self@channelid] adding callback
° [self@sys] not starting polling. waiting for autoJoin to finish
(node:83649) UnhandledPromiseRejectionWarning: nope!
(node:83649) 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 de 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: 1)
(node:83649) [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.

Tried with --unhandled-rejections=strict :

* autojoin all known channels
@ [self@undefined] adding callback
+ [self@<channel_id_here>] joined
@ [self@<channel_id_here>] adding callback
° [self@sys] not starting polling. waiting for autoJoin to finish
internal/process/promises.js:194
        triggerUncaughtException(err, true /* fromPromise */);
        ^

[UnhandledPromiseRejection: 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(). The promise rejected with the reason "nope!".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Am I doing something wrong ?
No error logs to check in my nextcloud server. I can see login worked.
Thanks for any help.

@Eisteed
Copy link
Author

Eisteed commented Jul 8, 2022

Found out the query response is 404
Replaced "Nope!" with res.status

Solution is to use v4 in url when checking room and v1 for the rest (using nextcloud 22 and newer)

Replacing (starting line 280)

    _request(path, opt = {}) {
        let url = this._buildURL(path);
        if (opt.query) {
            url += (url.includes('?') ? '&' : '?') + querystring.stringify(opt.query);
        }

With

    _request(path, opt = {}) {
        let url = this._buildURL(path);
        if (opt.query) {
            url += (url.includes('?') ? '&' : '?') + querystring.stringify(opt.query);
        }

        if(url.includes("room") == true){
            url = url.replace("v1", "v4");
        }

@webagroprom
Copy link

Nextcloud 24
Almalinux 8

  1. npm install nextcloud-talk-bot
  2. Create example mybot.js
// Import Class
const NextcloudTalkBot = require('nextcloud-talk-bot');

// Create instance w/ bot login data
const bot = new NextcloudTalkBot({
    server: 'https://nextcloud.domain.ru',
    user: 'next-boting',
    pass: 'passwd,
    autoJoin: true
});

// Simple usage; reacts to all channels the bot joined
bot.onText('Somebody in?', x => x.reply('Sure, because you are!'));

// Join a channel and react to it's contents (just returns channel if already joined)
const boppy = bot.getChannel('Telegram Channel here');

// Reaction bases on RegExp (simple)
boppy.onText(/^#echo /, msg => msg.reply(msg.text.substr(6), false));

// See examples dir for more examples

// Need to start polling
bot.startPolling(); 

run - node mybot.js

*@+@°(node:17888) UnhandledPromiseRejectionWarning: nope!
(node:17888) 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(). (rejection id: 1)
(node:17888) [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.

How to fix the error?
What to do wrong?

@webagroprom
Copy link

Edit: nextcloud-talk-bot.js

#7 (comment)

run: node mybot.js

*@+@°°1! [dy3ennzq] error nope!
1! [dy3ennzq] error nope!
1! [dy3ennzq] error nope!
1! [dy3ennzq] error nope!
1! [dy3ennzq] error nope!

@Eisteed
Copy link
Author

Eisteed commented Sep 15, 2022

Just read my 2nd post

Found out the query response is 404 Replaced "Nope!" with res.status

Solution is to use v4 in url when checking room and v1 for the rest (using nextcloud 22 and newer)

Replacing (starting line 280)

    _request(path, opt = {}) {
        let url = this._buildURL(path);
        if (opt.query) {
            url += (url.includes('?') ? '&' : '?') + querystring.stringify(opt.query);
        }

With

    _request(path, opt = {}) {
        let url = this._buildURL(path);
        if (opt.query) {
            url += (url.includes('?') ? '&' : '?') + querystring.stringify(opt.query);
        }

        if(url.includes("room") == true){
            url = url.replace("v1", "v4");
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants