From 632b88bd552bdce905b2873ab19e9c7c2ea87ee2 Mon Sep 17 00:00:00 2001 From: Mateusz Narowski Date: Tue, 7 Nov 2023 12:25:44 +0100 Subject: [PATCH] fix: add error handling for attempts to access pages with content-type other than json (#319) --- lib/lib/context.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/lib/context.js b/lib/lib/context.js index 07ecba58..7276f6eb 100644 --- a/lib/lib/context.js +++ b/lib/lib/context.js @@ -108,6 +108,11 @@ async function contextMiddleware (context) { const response = await app.$typo3.api.getPage(path) const { data } = response + const contentType = response.headers['content-type'] + if (contentType && !contentType.includes('application/json')) { + return setErrorContext(context, { response: { status: 415, message: 'Unsupported content-type: \'application/json\' expected.' } }) + } + if (context.res) { setResponseHeaders(context, response.headers) }