diff --git a/package-lock.json b/package-lock.json index f729e093..e61f4443 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@quintype/framework", - "version": "7.34.6", + "version": "7.34.7-handle-500-issue.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@quintype/framework", - "version": "7.34.6", + "version": "7.34.7-handle-500-issue.3", "license": "ISC", "dependencies": { "@ampproject/toolbox-optimizer": "2.8.3", diff --git a/package.json b/package.json index 73ea842f..9a95b1d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@quintype/framework", - "version": "7.34.6", + "version": "7.34.7-handle-500-issue.3", "description": "Libraries to help build Quintype Node.js apps", "main": "index.js", "engines": { diff --git a/server/handlers/isomorphic-handler.js b/server/handlers/isomorphic-handler.js index db6e4d12..e925b43c 100644 --- a/server/handlers/isomorphic-handler.js +++ b/server/handlers/isomorphic-handler.js @@ -125,7 +125,7 @@ function loadDataForPageType( .then((result) => { if (result && result.data) { if (result.data[ABORT_HANDLER] || (result.data.error && result.data.error.message)) { - return null + return null; } } return result; @@ -485,6 +485,11 @@ exports.handleIsomorphicRoute = function handleIsomorphicRoute( }); return res.redirect(301, result.data.location); } + + if (statusCode >= 500) { + return res.sendStatus(statusCode); + } + const seoInstance = getSeoInstance(seo, config, result.pageType); const seoTags = seoInstance && seoInstance.getMetaTags(config, result.pageType || match.pageType, result, { url }); diff --git a/test/integration/custom-route-handler-test.js b/test/integration/custom-route-handler-test.js index a0eaef03..28abb82a 100644 --- a/test/integration/custom-route-handler-test.js +++ b/test/integration/custom-route-handler-test.js @@ -48,8 +48,7 @@ function getClientStub(hostname) { page: { id: 103, title: "Testing", - content: - "Test

Heading

", + content: "Test

Heading

", metadata: { header: true, footer: false }, type: "static-page", "status-code": 200, @@ -60,8 +59,7 @@ function getClientStub(hostname) { page: { id: 104, title: "Testing", - content: - "Test

Heading

", + content: "Test

Heading

", metadata: { header: false, footer: false }, type: "static-page", "status-code": 200, @@ -72,8 +70,7 @@ function getClientStub(hostname) { page: { id: 105, title: "Testing mime type", - content: - "Test

Heading

", + content: "Test

Heading

", metadata: { header: false, footer: false, @@ -104,9 +101,7 @@ function createApp(loadData, routes, opts = {}) { generateRoutes: () => routes, loadData, renderLayout: (res, { contentTemplate, store }) => - res.send( - JSON.stringify({ contentTemplate, store: store.getState() }) - ), + res.send(JSON.stringify({ contentTemplate, store: store.getState() })), handleNotFound: false, publisherConfig: {}, }, @@ -126,10 +121,7 @@ describe("Custom Route Handler", function () { supertest(app) .get("/moved-permanently") .expect("Location", "/permanent-location") - .expect( - "Cache-Control", - "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400" - ) + .expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400") .expect("Vary", /Accept\-Encoding/) .expect("Surrogate-Key", "sp/42/101") .expect("Cache-Tag", "sp/42/101") @@ -144,10 +136,7 @@ describe("Custom Route Handler", function () { supertest(app) .get("/moved-temporarily") .expect("Location", "/temporary-location") - .expect( - "Cache-Control", - "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400" - ) + .expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400") .expect("Vary", /Accept\-Encoding/) .expect("Surrogate-Key", "sp/42/102") .expect("Cache-Tag", "sp/42/102") @@ -163,10 +152,7 @@ describe("Custom Route Handler", function () { supertest(app) .get("/static-with-header-footer") .expect("Content-Type", /html/) - .expect( - "Cache-Control", - "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400" - ) + .expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400") .expect("Vary", "Accept-Encoding") .expect("Surrogate-Key", "sp/42/103") .expect("Cache-Tag", "sp/42/103") @@ -188,19 +174,13 @@ describe("Custom Route Handler", function () { supertest(app) .get("/static-without-header-footer") .expect("Content-Type", /html/) - .expect( - "Cache-Control", - "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400" - ) + .expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400") .expect("Vary", "Accept-Encoding") .expect("Surrogate-Key", "sp/42/104") .expect("Cache-Tag", "sp/42/104") .expect(200) .then((res) => { - assert.equal( - "Test

Heading

", - res.text - ); + assert.equal("Test

Heading

", res.text); }) .then(done); }); @@ -233,9 +213,7 @@ describe("Custom Route Handler", function () { it("Store reads config and data from data-loader response", function (done) { const app = createApp( (pageType, params, config, client, { host, next }) => - pageType === "custom-static-page" - ? Promise.resolve({ data: { navigationMenu: [] }, config: {} }) - : next(), + pageType === "custom-static-page" ? Promise.resolve({ data: { navigationMenu: [] }, config: {} }) : next(), [{ pageType: "story-page", path: "/*" }] ); supertest(app) @@ -258,10 +236,7 @@ describe("Custom Route Handler", function () { supertest(app) .get("/moved-absolute") .expect("Location", "https://www.google.com") - .expect( - "Cache-Control", - "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400" - ) + .expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400") .expect("Vary", /Accept\-Encoding/) .expect("Surrogate-Key", "sp/42/105") .expect("Cache-Tag", "sp/42/105") @@ -275,10 +250,7 @@ describe("Custom Route Handler", function () { ); supertest(app) .get("/static-with-mime-type") - .expect( - "Cache-Control", - "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400" - ) + .expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400") .expect("Vary", /Accept\-Encoding/) .expect("Surrogate-Key", "sp/42/105") .expect("Cache-Tag", "sp/42/105") @@ -293,10 +265,7 @@ describe("Custom Route Handler", function () { ); supertest(app) .get("/static-without-header-footer") - .expect( - "Cache-Control", - "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400" - ) + .expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400") .expect("Vary", "Accept-Encoding") .expect("Surrogate-Key", "sp/42/104") .expect("Cache-Tag", "sp/42/104") diff --git a/test/integration/isomorphic-handler-test.js b/test/integration/isomorphic-handler-test.js index 6acbea94..f0950672 100644 --- a/test/integration/isomorphic-handler-test.js +++ b/test/integration/isomorphic-handler-test.js @@ -168,17 +168,7 @@ describe("Isomorphic Handler", function () { }), } ); - - supertest(app) - .get("/") - .expect("Content-Type", /html/) - .expect(500) - .then((res) => { - const response = JSON.parse(res.text); - assert.equal('
foobar
', response.content); - assert.equal(true, response.store.qt.disableIsomorphicComponent); - }) - .then(done, done); + supertest(app).get("/").expect(500, done); }); it("Throws a 500 if loadData and loadErrorData both crash", function (done) { @@ -194,7 +184,7 @@ describe("Isomorphic Handler", function () { } ); - supertest(app).get("/").expect("Content-Type", /html/).expect(500, done); + supertest(app).get("/").expect(500, done); }); it("Cache headers are set", function (done) { diff --git a/test/integration/url-redirect-test.js b/test/integration/url-redirect-test.js index 8ca1b0f6..be8e9763 100644 --- a/test/integration/url-redirect-test.js +++ b/test/integration/url-redirect-test.js @@ -508,10 +508,7 @@ describe("Redirect Routes Handler", function () { redirectUrls, } ); - supertest(app) - .get("/moved-permanently-1") - .expect("Location", "/permanent-location-1") - .expect(301, done); + supertest(app).get("/moved-permanently-1").expect("Location", "/permanent-location-1").expect(301, done); }); it("Redirects all the urls with status code to 302 if redirectUrls is present", function (done) { @@ -528,10 +525,7 @@ describe("Redirect Routes Handler", function () { ], } ); - supertest(app) - .get("/moved-temporarily-1") - .expect("Location", "/temporarily-location-1") - .expect(302, done); + supertest(app).get("/moved-temporarily-1").expect("Location", "/temporarily-location-1").expect(302, done); }); it("Renders homepage when redirect urls are present", function (done) { @@ -555,10 +549,7 @@ describe("Redirect Routes Handler", function () { .expect(200) .then((res) => { const response = JSON.parse(res.text); - assert.equal( - '
foobar
', - response.content - ); + assert.equal('
foobar
', response.content); assert.equal("foobar", response.store.qt.data.text); assert.equal("127.0.0.1", response.store.qt.data.host); assert.equal("home-page", response.store.qt.pageType); @@ -572,10 +563,7 @@ describe("Redirect Routes Handler", function () { [{ pageType: "story-page", path: "/*" }], { redirectUrls: getRedirectUrl } ); - supertest(app) - .get("/moved-permanently-1") - .expect("Location", "/permanent-location-1") - .expect(301, done); + supertest(app).get("/moved-permanently-1").expect("Location", "/permanent-location-1").expect(301, done); }); it("Should handle Route Parameters redirects properly", function (done) { @@ -584,10 +572,7 @@ describe("Redirect Routes Handler", function () { [{ pageType: "story-page", path: "/*" }], { redirectUrls: getRedirectUrl } ); - supertest(app) - .get("/india/news/some-slug") - .expect("Location", "/india/some-slug") - .expect(301, done); + supertest(app).get("/india/news/some-slug").expect("Location", "/india/some-slug").expect(301, done); }); it("Should handle multiple Route Parameters redirects properly", function (done) { @@ -596,10 +581,7 @@ describe("Redirect Routes Handler", function () { [{ pageType: "story-page", path: "/*" }], { redirectUrls: getRedirectUrl } ); - supertest(app) - .get("/india/foo/some-slug/slug") - .expect("Location", "/india/some-slug") - .expect(302, done); + supertest(app).get("/india/foo/some-slug/slug").expect("Location", "/india/some-slug").expect(302, done); }); it("Should handle interchanging route parameter redirects properly", function (done) { @@ -608,10 +590,7 @@ describe("Redirect Routes Handler", function () { [{ pageType: "story-page", path: "/*" }], { redirectUrls: getRedirectUrl } ); - supertest(app) - .get("/foo/something/bar") - .expect("Location", "/bar/something/foo") - .expect(301, done); + supertest(app).get("/foo/something/bar").expect("Location", "/bar/something/foo").expect(301, done); }); it("Should handle external redirects", function (done) { @@ -620,10 +599,7 @@ describe("Redirect Routes Handler", function () { [{ pageType: "story-page", path: "/*" }], { redirectUrls: getRedirectUrl } ); - supertest(app) - .get("/something/new") - .expect("Location", "https://www.google.com/something") - .expect(301, done); + supertest(app).get("/something/new").expect("Location", "https://www.google.com/something").expect(301, done); }); it("Should handle external redirects with params", function (done) { @@ -632,10 +608,7 @@ describe("Redirect Routes Handler", function () { [{ pageType: "story-page", path: "/*" }], { redirectUrls: getRedirectUrl } ); - supertest(app) - .get("/something/new1") - .expect("Location", "https://www.google.com/new1") - .expect(301, done); + supertest(app).get("/something/new1").expect("Location", "https://www.google.com/new1").expect(301, done); }); it("Should not crash if redirectUrls is not present", function (done) { @@ -646,10 +619,7 @@ describe("Redirect Routes Handler", function () { supertest(app) .get("/moved-temporarily-1") .expect("Location", "/temporarily-location-1") - .expect( - "Cache-Control", - "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400" - ) + .expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400") .expect("Vary", /Accept\-Encoding/) .expect("Surrogate-Key", "sp/42/102") .expect("Cache-Tag", "sp/42/102")