How to use the verror.hasCauseWithName function in verror

To help you get started, we’ve selected a few verror 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 joyent / sdc-docker / lib / backends / sdc / volumes.js View on Github external
}, function onGetVolume(err, updatedVolume) {
            if (err && verror.hasCauseWithName(err, 'VolumeNotFoundError')) {
                // If the VM is not found, no use in polling further and we
                // return the error in case the caller wanted to know when the
                // volume disappeared.
                callback(err);
                return;
            }

            if (updatedVolume && states.indexOf(updatedVolume.state) !== -1) {
                callback(null, updatedVolume);
            } else {
                if (nbVolumeStatePolled > MAX_VOLUME_STATE_POLLS) {
                    callback(new Error('Timed out polling for '
                        + 'volume state change'), updatedVolume);
                } else {
                    setTimeout(doPollVolumeStateChange,
                        VOLUME_STATE_POLL_INTERVAL_IN_MS);
github joyent / sdc-adminui / lib / settings.js View on Github external
client.getObject(ADMINUI_BUCKET, 'settings', function (err) {
            if (err && verror.hasCauseWithName(err, 'ObjectNotFoundError')) {
                client.putObject(ADMINUI_BUCKET, 'settings', {}, function (putErr, obj) {
                    if (putErr) {
                        client.log.info('error adding settings key');
                    } else {
                        client.log.info('added key: settings');
                    }
                });
            }

            if (err) {
                client.log.info(err, 'error adding settings key');
            }

            client.log.info('settings key OK');
        });
    }
github joyent / sdc-adminui / lib / sessions.js View on Github external
this.client.deleteMany(SESSIONS_BUCKET, filter, function (err) {
        if (err) {
            if (!verror.hasCauseWithName(err, 'ObjectNotFoundError')) {
                log.error(err, 'failed to delete expired sessions');
            }
        } else {
            log.trace('deleted expired sessions');
        }
    });
};
github joyent / sdc-adminui / lib / notes.js View on Github external
client.getBucket(NOTES_BUCKET, function (err) {
        if (err) {
            if (verror.hasCauseWithName(err, 'BucketNotFoundError')) {
                client.log.info('creating sdcnotes bucket');
                client.createBucket(NOTES_BUCKET, cfg, function (err2) {
                    if (err2) {
                        client.log.fatal(err2, 'error creating sdcnotes bucket');
                    } else {
                        client.log.info('created sdcnotes created');
                    }
                });
            } else {
                client.log.fatal(err, 'error retrieving sdcnotes bucket');
            }
        }
    });
}
github joyent / sdc-adminui / lib / sessions.js View on Github external
this.client.getObject(SESSIONS_BUCKET, id, function (err, obj) {
        self.log.debug('session.get cb', err, obj);
        if (err) {
            if (verror.hasCauseWithName(err, 'ObjectNotFoundError')) {
                self.log.debug('session doesn\'t exist %s', id);
                return cb(null, null);
            } else {
                self.log.error(err);
                return cb(err);
            }
        }

        if (obj.value.expires < (new Date().getTime())) {
            self.log.debug('session expired %s', id);
            self.destroy(id);
            return cb(null, null);
        }

        var data = obj.value;
        if (null === data) {
github joyent / sdc-adminui / lib / sessions.js View on Github external
this.client.getBucket(SESSIONS_BUCKET, function (err) {
        if (err) {
            if (verror.hasCauseWithName(err, 'BucketNotFoundError')) {
                this._createBucket();
            } else {
                this.log.fatal(err, 'error retrieving sessions bucket');
            }
        } else {
            this.ready();
            this.log.info('sessions bucket ready.');
        }
    }.bind(this));
};
github joyent / moray / lib / pg.js View on Github external
this.pool.claim(function afterClaim(err, h, client) {
        if (err) {
            if (VError.hasCauseWithName(err, 'PoolFailedError')) {
                callback(createNoBackendError());
                return;
            }

            if (VError.hasCauseWithName(err, 'ClaimTimeoutError')) {
                if (stats.idleConnections === 0 &&
                    (stats.totalConnections - stats.pendingConnections) <= 2) {
                    /*
                     * We need to disambiguate the case where we have timed out
                     * because we can't connect to the database, so that we can
                     * return an appropriate error indicating whether we're just
                     * overloaded, or service is completely unavailable.
                     *
                     * When all of our connection slots are trying to connect,
                     * then we assume that the database is currently down. The
                     * possible difference of 2 is to handle the point where a
                     * connection slot has failed, and still counts towards
                     * total connections but not pending connections.
                     */
                    callback(createNoBackendError());
                } else {
github joyent / moray / lib / pg.js View on Github external
this.pool.claim(function afterClaim(err, h, client) {
        if (err) {
            if (VError.hasCauseWithName(err, 'PoolFailedError')) {
                callback(createNoBackendError());
                return;
            }

            if (VError.hasCauseWithName(err, 'ClaimTimeoutError')) {
                if (stats.idleConnections === 0 &&
                    (stats.totalConnections - stats.pendingConnections) <= 2) {
                    /*
                     * We need to disambiguate the case where we have timed out
                     * because we can't connect to the database, so that we can
                     * return an appropriate error indicating whether we're just
                     * overloaded, or service is completely unavailable.
                     *
                     * When all of our connection slots are trying to connect,
                     * then we assume that the database is currently down. The
                     * possible difference of 2 is to handle the point where a
github joyent / sdc-adminui / lib / settings.js View on Github external
client.getBucket(ADMINUI_BUCKET, function (getErr) {
        if (getErr) {
            if (verror.hasCauseWithName(getErr, 'BucketNotFoundError')) {
                client.log.info('adminui moray bucket not found, creating...');
                client.createBucket(ADMINUI_BUCKET, ADMINUI_BUCKET_CFG, function (createErr) {
                    if (createErr) {
                        client.log.fatal(createErr, 'error creating settings bucket: %s', createErr.message);
                        return null;
                    }
                    onBucketReady();
                    return null;
                });
                return null;
            }
            client.log.fatal(getErr, 'error retrieving settings bucket from moray');
        } else {
            onBucketReady();
        }
        return null;
github pmarkert / hyperpotamus / lib / actions / request.js View on Github external
.catch(err => {
			if (err instanceof context.ProcessingDirective || verror.hasCauseWithName(err, "ResponseActionError")) {
				throw err;
			}
			throw new verror.VError({
				name: "ResponseActionError",
				cause: err,
				info: {
					request: context.getSessionValue("hyperpotamus.request"),
					response:  _.pick(context.getSessionValue("hyperpotamus.response", null, null), ["statusCode", "headers", "body"])
				},
			}, "Error processing post-response actions for request");
		})
		.finally(() => {