How to use the nats.NatsError function in nats

To help you get started, we’ve selected a few nats examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nats-io / stan.js / lib / stan.js View on Github external
this.nc.requestOne(this.subRequests, Buffer.from(sr.serializeBinary()), this.options.connectTimeout, (msg) => {
        if (msg instanceof nats.NatsError) {
            if (msg.code === nats.REQ_TIMEOUT) {
                const err = new nats.NatsError(SUB_REQ_TIMEOUT, SUB_REQ_TIMEOUT, msg);
                retVal.emit('timeout', err);
            } else {
                retVal.emit('error', msg);
            }
            return;
        }
        //noinspection JSUnresolvedVariable
        const r = proto.pb.SubscriptionResponse.deserializeBinary(Buffer.from(msg, 'binary'));
        const err = r.getError();
        if (err && err.length !== 0) {
            retVal.emit('error', new Error(err));
            this.nc.unsubscribe(retVal.inboxSub);
            retVal.emit('unsubscribed');
            return;
        }
        retVal.ackInbox = r.getAckInbox();
github nats-io / stan.js / lib / stan.js View on Github external
sc.nc.requestOne(reqSubject, Buffer.from(ur.serializeBinary()), sc.options.connectTimeout, (msg) => {
        let err;
        if (msg instanceof nats.NatsError) {
            const type = doClose ? CLOSE_REQ_TIMEOUT : UNSUB_REQ_TIMEOUT;
            err = new nats.NatsError(type, type, msg);
            if (msg.code === nats.REQ_TIMEOUT) {
                this.emit('timeout', err);
            } else {
                this.emit('error', err);
            }
            return;
        }
        //noinspection JSUnresolvedVariable
        const r = proto.pb.SubscriptionResponse.deserializeBinary(Buffer.from(msg, 'binary'));
        err = r.getError();
        if (err && err.length > 0) {
            this.emit('error', new Error(r.getError()));
        } else {
            this.emit(doClose ? 'closed' : 'unsubscribed');
        }
    });
github nats-io / stan.js / lib / stan.js View on Github external
this.nc.requestOne(discoverSubject, Buffer.from(req.serializeBinary()), this.options.connectTimeout, (msg) => {
            if (msg instanceof nats.NatsError) {
                let err = msg;
                if (msg.code === nats.REQ_TIMEOUT) {
                    err = new nats.NatsError(CONNECT_REQ_TIMEOUT, CONNECT_REQ_TIMEOUT, err);
                }
                this.closeWithError('error', err);
                return;
            }

            const cr = proto.pb.ConnectResponse.deserializeBinary(Buffer.from(msg, 'binary'));
            if (cr.getError() !== "") {
                this.closeWithError('error', cr.getError());
                return;
            }
            this.pubPrefix = cr.getPubPrefix();
            this.subRequests = cr.getSubRequests();
            this.unsubRequests = cr.getUnsubRequests();
            this.subCloseRequests = cr.getSubCloseRequests();
            this.closeRequests = cr.getCloseRequests();

nats

Node.js client for NATS, a lightweight, high-performance cloud native messaging system

Apache-2.0
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis