improve on a DEPTH_ZERO_SELF_SIGNED_CERT error

from:
    triton account: error: DEPTH_ZERO_SELF_SIGNED_CERT
to this:
    triton account: error (SelfSignedCert): could not access CloudAPI https://10.88.88.3 because it uses a self-signed TLS certificate and your current profile is not configured for insecure access: DEPTH_ZERO_SELF_SIGNED_CERT
This commit is contained in:
Trent Mick 2015-09-23 21:08:26 -07:00
parent ee07395eae
commit b238fcf52f
3 changed files with 35 additions and 1 deletions

View File

@ -309,7 +309,7 @@ function main(argv) {
var showErr = (cli.showErr !== undefined ? cli.showErr : true);
if (err && showErr) {
var code = (err.body ? err.body.code : err.code);
var code = (err.body ? err.body.code : err.code) || err.restCode;
if (code === 'NoCommand') {
/* jsl:pass */
} else if (err.message !== undefined) {

View File

@ -247,6 +247,7 @@ CloudApi.prototype._request = function _request(options, callback) {
*/
CloudApi.prototype._passThrough =
function _passThrough(endpoint, opts, cb) {
var self = this;
if (typeof (opts) === 'function') {
cb = opts;
opts = null;
@ -259,6 +260,21 @@ function _passThrough(endpoint, opts, cb) {
var p = this._path(endpoint, opts);
this._request(p, function (err, req, res, body) {
/*
* Improve this kind of error message:
*
* Error: DEPTH_ZERO_SELF_SIGNED_CERT
* at SecurePair.<anonymous> (tls.js:1381:32)
* at SecurePair.emit (events.js:92:17)
*
* TODO: could generalize this into a wrapErr method.
*/
if (err && err.message === 'DEPTH_ZERO_SELF_SIGNED_CERT' &&
self.client.rejectUnauthorized)
{
err = new errors.SelfSignedCertError(err, self.url);
}
cb(err, body, res);
});
};

View File

@ -113,6 +113,23 @@ function SigningError(cause) {
util.inherits(SigningError, TritonError);
/**
* A 'DEPTH_ZERO_SELF_SIGNED_CERT' An error signing a request.
*/
function SelfSignedCertError(cause, url) {
var msg = format('could not access CloudAPI %s because it uses a ' +
'self-signed TLS certificate and your current profile is not ' +
'configured for insecure access', url);
TritonError.call(this, {
cause: cause,
message: msg,
code: 'SelfSignedCert',
exitStatus: 1
});
}
util.inherits(SelfSignedCertError, TritonError);
/**
* Multiple errors in a group.
*/
@ -143,6 +160,7 @@ module.exports = {
ConfigError: ConfigError,
UsageError: UsageError,
SigningError: SigningError,
SelfSignedCertError: SelfSignedCertError,
MultiError: MultiError
};
// vim: set softtabstop=4 shiftwidth=4: