alexkander / loopback-socket

Loopback module for create Socket.io connections and allow call methods and make subscriptions
MIT License
6 stars 2 forks source link

Promise rejection #3

Closed mkilp closed 5 years ago

mkilp commented 5 years ago

Sup!

I ran into a problem with custom handlers:

  function addUser(socket, credentials, args, cb) {
    socket.join(args.eventId);
    socket.username = args.username;
    socket.userId = args.userId;
    socket.eventId = args.eventId;
    let user = app.models.JoinallyUser.findById(args.userId, {
      fields: {
        firstname: true,
        birthdate: true,
        pictureId: true,
        sex: true,
      },
    }).then((user) => {
      onlineUsers['args.userId'] = user;
    });
    debug('User ' + args.username + ' joined Eventroom with ID ' +
      args.eventId);
    ++numUsers;

    socket.emit('login', {
      numUsers: numUsers,
    });
    socket.to(args.eventId).emit('user joined', {
      username: args.username,
      numUsers: numUsers,
    });
    cb(null, true);
  }

[...]
  socket.defineMethod('add user', addUser);

Error Log:

(node:26029) UnhandledPromiseRejectionWarning: TypeError: done is not a function at Promise.resolve.then.then.catch.then (/root/devBetaBackend/node_modules/loopback-socket/lib/loopback-socket.js:52:7) at at process._tickCallback (internal/process/next_tick.js:188:7) (node:26029) 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:26029) [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.

Any idea what I could be doing wrong? :)

Thanks,

Marvin / Nop0x

alexkander commented 5 years ago

Hi @Nop0x.

I think you are emitting the 'add user' event in the client without a response handler. I have release 0.4.2 version to fix this issue.

Please let me know if you have any other problem.

Regards.