-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into pro-4733-npm-workspace-support
* main: hotfix for logging non-Error exceptions from api routes typo works update confirm message replace --force with --confirm + remove prompts for hosted customer users add --force to skip prompt remove stray log use prompts and update changelog figure should reset the wrapper handle paragraph without texts add lint-fix and remove-empty-paragraph task to rich-text
- Loading branch information
Showing
5 changed files
with
264 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const t = require('../test-lib/test.js'); | ||
const assert = require('assert'); | ||
|
||
describe('Don\'t crash on weird API errors', function() { | ||
|
||
after(async function() { | ||
return t.destroy(apos); | ||
}); | ||
|
||
this.timeout(t.timeout); | ||
|
||
let apos; | ||
|
||
it('should initialize apos', async function() { | ||
apos = await t.create({ | ||
root: module, | ||
modules: { | ||
'api-test': { | ||
apiRoutes(self) { | ||
return { | ||
get: { | ||
fetchItFine(req) { | ||
return { | ||
nifty: true | ||
}; | ||
}, | ||
fetchItFailWeird(req) { | ||
throw 'not-an-error-object'; | ||
}, | ||
fetchItFailNormal(req) { | ||
throw new Error('normal error'); | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
it('should fetch fine in the normal case', async function() { | ||
const body = await apos.http.get('/api/v1/api-test/fetch-it-fine', {}); | ||
assert(typeof body === 'object'); | ||
assert.strictEqual(body.nifty, true); | ||
}); | ||
it('should fail politely in the weird case of a non-Error exception', async function() { | ||
let msgWas; | ||
const consoleError = console.error; | ||
console.error = msg => { | ||
msgWas = msg; | ||
}; | ||
try { | ||
await apos.http.get('/api/v1/api-test/fetch-it-fail-weird', {}); | ||
// Should not get here | ||
assert(false); | ||
} catch (e) { | ||
// Make sure the logging system itself is not at fault | ||
assert(!msgWas.toString().includes('Structured logging error')); | ||
} finally { | ||
console.error = consoleError; | ||
console.error(msgWas); | ||
} | ||
}); | ||
it('should fail politely in the normal case of an Error exception', async function() { | ||
let msgWas; | ||
const consoleError = console.error; | ||
console.error = msg => { | ||
msgWas = msg; | ||
}; | ||
try { | ||
await apos.http.get('/api/v1/api-test/fetch-it-fail-normal', {}); | ||
// Should not get here | ||
assert(false); | ||
} catch (e) { | ||
// Make sure the logging system itself is not at fault | ||
assert(!msgWas.toString().includes('Structured logging error')); | ||
} finally { | ||
console.error = consoleError; | ||
console.error(msgWas); | ||
} | ||
}); | ||
}); |