docs: sync error messages to docs

This commit is contained in:
AJ ONeal 2021-10-21 14:19:23 -06:00
parent 4c85fc4009
commit 076246e4d0
2 changed files with 51 additions and 24 deletions

View File

@ -279,22 +279,21 @@ SemVer Compatibility:
- `message` is **NOT** included in the semver compatibility guarantee (we intend to make them more client-friendly), neither is `detail` at this time (but it will be once we decide on what it should be). - `message` is **NOT** included in the semver compatibility guarantee (we intend to make them more client-friendly), neither is `detail` at this time (but it will be once we decide on what it should be).
- `details` may be added to, but not subtracted from - `details` may be added to, but not subtracted from
| Hint | Code | Status | Message (truncated) | | Hint | Code | Status | Message (truncated) |
| ------------------- | --------------- | ------ | ------------------------------------------------ | | ----------------- | ------------- | ------ | ------------------------------------------------------ |
| (developer error) | DEVELOPER_ERROR | 500 | test... | | bad gateway | BAD_GATEWAY | 502 | The auth token could not be verified because our se... |
| (bad gateway) | BAD_GATEWAY | 502 | The token could not be verified because our s... | | insecure issuer | MALFORMED_JWT | 400 | The auth token could not be verified because our se... |
| (insecure issuer) | MALFORMED_JWT | 400 | The token could not be verified because our s... | | parse error | MALFORMED_JWT | 400 | The auth token could not be verified because it is ... |
| (parse error) | MALFORMED_JWT | 400 | The auth token is malformed.... | | no issuer | MALFORMED_JWT | 400 | The auth token could not be verified because it doe... |
| (no issuer) | MALFORMED_JWT | 400 | The token could not be verified because it do... | | malformed exp | MALFORMED_JWT | 400 | The auth token could not be verified because it's e... |
| (malformed exp) | MALFORMED_JWT | 400 | The auth token could not be verified because ... | | expired | INVALID_JWT | 401 | The auth token is expired. To try again, go to the ... |
| (expired) | INVALID_JWT | 401 | The auth token is expired. To try again, go t... | | inactive | INVALID_JWT | 401 | The auth token isn't valid yet. It's activation dat... |
| (inactive) | INVALID_JWT | 401 | The auth token isn't valid yet. It's activati... | | bad signature | INVALID_JWT | 401 | The auth token did not pass verification because it... |
| (bad signature) | INVALID_JWT | 401 | The auth token did not pass verification beca... | | jwk not found old | INVALID_JWT | 401 | The auth token did not pass verification because ou... |
| (jwk not found old) | INVALID_JWT | 401 | The auth token did not pass verification beca... | | jwk not found | INVALID_JWT | 401 | The auth token did not pass verification because ou... |
| (jwk not found) | INVALID_JWT | 401 | The auth token did not pass verification beca... | | no jwkws uri | INVALID_JWT | 401 | The auth token did not pass verification because it... |
| (no jwkws uri) | INVALID_JWT | 401 | The auth token did not pass verification beca... | | unknown issuer | INVALID_JWT | 401 | The auth token did not pass verification because it... |
| (unknown issuer) | INVALID_JWT | 401 | The auth token did not pass verification beca... | | failed claims | INVALID_JWT | 401 | The auth token did not pass verification because it... |
| (failed claims) | INVALID_JWT | 401 | The auth token did not pass verification beca... |
# Change Log # Change Log

View File

@ -76,7 +76,7 @@ module.exports = {
}, },
BAD_GATEWAY: function (err) { BAD_GATEWAY: function (err) {
var msg = var msg =
"The token could not be verified because our server encountered a network error (or a bad gateway) when connecting to its issuing server."; "The auth token could not be verified because our server encountered a network error (or a bad gateway) when connecting to its issuing server.";
var details = []; var details = [];
if (err.message) { if (err.message) {
details.push("error.message = " + err.message); details.push("error.message = " + err.message);
@ -103,7 +103,7 @@ module.exports = {
"DEBUG: Set ENV 'KEYFETCH_ALLOW_INSECURE_HTTP=true' to allow insecure issuers (for testing)." "DEBUG: Set ENV 'KEYFETCH_ALLOW_INSECURE_HTTP=true' to allow insecure issuers (for testing)."
]; ];
var msg = var msg =
'The token could not be verified because our server could connect to its issuing server ("iss") securely.'; 'The auth token could not be verified because our server could connect to its issuing server ("iss") securely.';
return create(old, msg, E_MALFORMED, 400, details); return create(old, msg, E_MALFORMED, 400, details);
}, },
/** /**
@ -112,7 +112,7 @@ module.exports = {
*/ */
PARSE_ERROR: function (jwt) { PARSE_ERROR: function (jwt) {
var old = "could not parse jwt: '" + jwt + "'"; var old = "could not parse jwt: '" + jwt + "'";
var msg = "The auth token is malformed."; var msg = "The auth token could not be verified because it is malformed.";
var details = ["jwt = " + JSON.stringify(jwt)]; var details = ["jwt = " + JSON.stringify(jwt)];
return create(old, msg, E_MALFORMED, 400, details); return create(old, msg, E_MALFORMED, 400, details);
}, },
@ -122,7 +122,7 @@ module.exports = {
*/ */
NO_ISSUER: function (iss) { NO_ISSUER: function (iss) {
var old = "'iss' is not defined"; var old = "'iss' is not defined";
var msg = 'The token could not be verified because it doesn\'t specify an issuer ("iss").'; var msg = 'The auth token could not be verified because it doesn\'t specify an issuer ("iss").';
var details = ["jwt.claims.iss = " + JSON.stringify(iss)]; var details = ["jwt.claims.iss = " + JSON.stringify(iss)];
return create(old, msg, E_MALFORMED, 400, details); return create(old, msg, E_MALFORMED, 400, details);
}, },
@ -226,17 +226,45 @@ var Errors = module.exports;
// for README // for README
if (require.main === module) { if (require.main === module) {
console.info("| Hint | Code | Status | Message (truncated) |"); let maxWidth = 54;
console.info("| ---- | ---- | ------ | ------------------- |"); let header = ["Hint", "Code", "Status", "Message (truncated)"];
let widths = header.map(function (v) {
return Math.min(maxWidth, String(v).length);
});
let rows = [];
Object.keys(module.exports).forEach(function (k) { Object.keys(module.exports).forEach(function (k) {
//@ts-ignore //@ts-ignore
var E = module.exports[k]; var E = module.exports[k];
var e = E("test"); var e = E("test");
var code = e.code; var code = e.code;
var msg = e.message.slice(0, 45); var msg = e.message;
var hint = k.toLowerCase().replace(/_/g, " "); var hint = k.toLowerCase().replace(/_/g, " ");
console.info(`| (${hint}) | ${code} | ${e.status} | ${msg}... |`); widths[0] = Math.max(widths[0], String(hint).length);
widths[1] = Math.max(widths[1], String(code).length);
widths[2] = Math.max(widths[2], String(e.status).length);
widths[3] = Math.min(maxWidth, Math.max(widths[3], String(msg).length));
rows.push([hint, code, e.status, msg]);
}); });
rows.forEach(function (cols, i) {
let cells = cols.map(function (col, i) {
if (col.length > maxWidth) {
col = col.slice(0, maxWidth - 3);
col += "...";
}
return String(col).padEnd(widths[i], " ");
});
let out = `| ${cells[0]} | ${cells[1]} | ${cells[2]} | ${cells[3].slice(0, widths[3])} |`;
//out = out.replace(/\| /g, " ").replace(/\|/g, "");
console.info(out);
if (i === 0) {
cells = cols.map(function (col, i) {
return "-".padEnd(widths[i], "-");
});
console.info(`| ${cells[0]} | ${cells[1]} | ${cells[2]} | ${cells[3]} |`);
}
});
console.log();
console.log(Errors.MALFORMED_EXP()); console.log(Errors.MALFORMED_EXP());
console.log();
console.log(JSON.stringify(Errors.MALFORMED_EXP(), null, 2)); console.log(JSON.stringify(Errors.MALFORMED_EXP(), null, 2));
} }