Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge hotfix back to main #4287

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ structure. For consistent results, one might also choose to override the `render
methods of the `@apostrophecms/area` module, which are used to render content while editing.
Thanks to Michelin for their support of this work.

## 3.55.0
## 3.55.1 (2023-09-11)

### Fixes

* The structured logging for API routes now responds properly if an API route throws a `string` as an exception, rather than
a politely `Error`-derived object with a `stack` property. Previously this resulted in an error message about the logging
system itself, which was not useful for debugging the original exception.

## 3.55.0 (2023-08-30)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datestamp was missing.


### Adds

Expand Down
2 changes: 1 addition & 1 deletion modules/@apostrophecms/module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ module.exports = {
self.logError(req, `api-error${typeTrail}`, msg, {
name: response.name,
status: response.code,
stack: error.stack.split('\n').slice(1).map(line => line.trim()),
stack: (error.stack || '').split('\n').slice(1).map(line => line.trim()),
errorPath: response.path,
data: response.data
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apostrophe",
"version": "3.55.0",
"version": "3.55.1",
"description": "The Apostrophe Content Management System.",
"main": "index.js",
"scripts": {
Expand Down
81 changes: 81 additions & 0 deletions test/weird-api-errors.js
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);
}
});
});
Loading