-
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 pull request #4287 from apostrophecms/pro-4779-base
Merge hotfix back to main
- Loading branch information
Showing
4 changed files
with
92 additions
and
3 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
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); | ||
} | ||
}); | ||
}); |