apostrophe 3.55.0 → 3.55.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.55.1
4
+
5
+ ### Fixes
6
+
7
+ * The structured logging for API routes now responds properly if an API route throws a `string` as an exception, rather than
8
+ a politely `Error`-derived object with a `stack` property. Previously this resulted in an error message about the logging
9
+ system itself, which was not useful for debugging the original exception.
10
+
3
11
  ## 3.55.0
4
12
 
5
13
  ### Adds
@@ -258,7 +258,7 @@ module.exports = {
258
258
  self.logError(req, `api-error${typeTrail}`, msg, {
259
259
  name: response.name,
260
260
  status: response.code,
261
- stack: error.stack.split('\n').slice(1).map(line => line.trim()),
261
+ stack: (error.stack || '').split('\n').slice(1).map(line => line.trim()),
262
262
  errorPath: response.path,
263
263
  data: response.data
264
264
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apostrophe",
3
- "version": "3.55.0",
3
+ "version": "3.55.1",
4
4
  "description": "The Apostrophe Content Management System.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,81 @@
1
+ const t = require('../test-lib/test.js');
2
+ const assert = require('assert');
3
+
4
+ describe('Don\'t crash on weird API errors', function() {
5
+
6
+ after(async function() {
7
+ return t.destroy(apos);
8
+ });
9
+
10
+ this.timeout(t.timeout);
11
+
12
+ let apos;
13
+
14
+ it('should initialize apos', async function() {
15
+ apos = await t.create({
16
+ root: module,
17
+ modules: {
18
+ 'api-test': {
19
+ apiRoutes(self) {
20
+ return {
21
+ get: {
22
+ fetchItFine(req) {
23
+ return {
24
+ nifty: true
25
+ };
26
+ },
27
+ fetchItFailWeird(req) {
28
+ throw 'not-an-error-object';
29
+ },
30
+ fetchItFailNormal(req) {
31
+ throw new Error('normal error');
32
+ }
33
+ }
34
+ };
35
+ }
36
+ }
37
+ }
38
+ });
39
+ });
40
+ it('should fetch fine in the normal case', async function() {
41
+ const body = await apos.http.get('/api/v1/api-test/fetch-it-fine', {});
42
+ assert(typeof body === 'object');
43
+ assert.strictEqual(body.nifty, true);
44
+ });
45
+ it('should fail politely in the weird case of a non-Error exception', async function() {
46
+ let msgWas;
47
+ const consoleError = console.error;
48
+ console.error = msg => {
49
+ msgWas = msg;
50
+ };
51
+ try {
52
+ await apos.http.get('/api/v1/api-test/fetch-it-fail-weird', {});
53
+ // Should not get here
54
+ assert(false);
55
+ } catch (e) {
56
+ // Make sure the logging system itself is not at fault
57
+ assert(!msgWas.toString().includes('Structured logging error'));
58
+ } finally {
59
+ console.error = consoleError;
60
+ console.error(msgWas);
61
+ }
62
+ });
63
+ it('should fail politely in the normal case of an Error exception', async function() {
64
+ let msgWas;
65
+ const consoleError = console.error;
66
+ console.error = msg => {
67
+ msgWas = msg;
68
+ };
69
+ try {
70
+ await apos.http.get('/api/v1/api-test/fetch-it-fail-normal', {});
71
+ // Should not get here
72
+ assert(false);
73
+ } catch (e) {
74
+ // Make sure the logging system itself is not at fault
75
+ assert(!msgWas.toString().includes('Structured logging error'));
76
+ } finally {
77
+ console.error = consoleError;
78
+ console.error(msgWas);
79
+ }
80
+ });
81
+ });