hemerajs / hapi-hemera

Hapi plugin to integrate Hemera.
MIT License
16 stars 7 forks source link

How can i catch custom error? #2

Closed imatefx closed 7 years ago

imatefx commented 7 years ago

How can i catch a custom error

const UnauthorizedError = Hemera.createError("Unauthorized")

hemera.add({
 topic: "math"
}, function (req, cb) {
 const err = new UnauthorizedError("Unauthorized action")
 cb(err)
})

I am not able to log any messages when using below code

  reply.act({
    topic: "math"
  }, (err, result) => {

    const error1 = err // BusinessError
    const error2 = err.cause // CustomError
    const root = err.rootCause // CustomError

    console.log(error1, error2, root);

    console.log('****************', result);
    console.log('****************', err);

    return reply(err || result);
  });
StarpTech commented 7 years ago

@imatefx did you also start NATS?

StarpTech commented 7 years ago

@imatefx I found it! with reply.act you send the payload directly to the caller it doesnt accept a callback https://github.com/hemerajs/hapi-hemera/blob/master/lib/index.js#L43. If you want to work with the hemera interface use request.hemera.act or server.hemera.act

imatefx commented 7 years ago

Thanks, it worked !!