Skip to content

Commit

Permalink
fix: hide AggregateError message stack
Browse files Browse the repository at this point in the history
closes #336
  • Loading branch information
panva committed Feb 26, 2021
1 parent 588bee9 commit 3011cca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,13 @@ class Issuer {
(discoveryURL) => wellKnownUri.startsWith(discoveryURL),
),
});
}));
})).catch((err) => {
if (err instanceof pAny.AggregateError) {
err.message = `Issuer.discover() failed.${err.message.split('\n')
.filter((line) => !line.startsWith(' at')).join('\n')}`;
}
throw err;
});
}

/* istanbul ignore next */
Expand Down
12 changes: 12 additions & 0 deletions test/issuer/discover_issuer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ describe('Issuer#discover()', () => {
return Issuer.discover('https://op.example.com')
.then(fail, function (error) {
expect(error.name).to.equal('AggregateError');
expect(error.message).to.match(/^Issuer\.discover\(\) failed\.\n/);
expect(error.message).not.to.contain('node_modules');
expect([...error].some((err) => {
try {
expect(err.name).to.equal('OPError');
Expand Down Expand Up @@ -242,6 +244,8 @@ describe('Issuer#discover()', () => {
return Issuer.discover('https://op.example.com')
.then(fail, function (error) {
expect(error.name).to.equal('AggregateError');
expect(error.message).to.match(/^Issuer\.discover\(\) failed\.\n/);
expect(error.message).not.to.contain('node_modules');
expect([...error].some((err) => {
try {
expect(err.name).to.equal('OPError');
Expand All @@ -263,6 +267,8 @@ describe('Issuer#discover()', () => {
return Issuer.discover('https://op.example.com')
.then(fail, function (error) {
expect(error.name).to.equal('AggregateError');
expect(error.message).to.match(/^Issuer\.discover\(\) failed\.\n/);
expect(error.message).not.to.contain('node_modules');
expect([...error].some((err) => {
try {
expect(err.name).to.equal('OPError');
Expand All @@ -284,6 +290,8 @@ describe('Issuer#discover()', () => {
return Issuer.discover('https://op.example.com')
.then(fail, function (error) {
expect(error.name).to.equal('AggregateError');
expect(error.message).to.match(/^Issuer\.discover\(\) failed\.\n/);
expect(error.message).not.to.contain('node_modules');
expect([...error].some((err) => {
try {
expect(err.name).to.eql('ParseError');
Expand All @@ -305,6 +313,8 @@ describe('Issuer#discover()', () => {
return Issuer.discover('https://op.example.com')
.then(fail, function (error) {
expect(error.name).to.equal('AggregateError');
expect(error.message).to.match(/^Issuer\.discover\(\) failed\.\n/);
expect(error.message).not.to.contain('node_modules');
expect([...error].some((err) => {
try {
expect(err.name).to.equal('OPError');
Expand All @@ -325,6 +335,8 @@ describe('Issuer#discover()', () => {
return Issuer.discover('https://op.example.com')
.then(fail, function (error) {
expect(error.name).to.equal('AggregateError');
expect(error.message).to.match(/^Issuer\.discover\(\) failed\.\n/);
expect(error.message).not.to.contain('node_modules');
expect([...error].some((err) => {
try {
expect(err.name).to.equal('OPError');
Expand Down

0 comments on commit 3011cca

Please sign in to comment.