From a48805257303aebe5b0dc4ffb469f3e1b3df4ef1 Mon Sep 17 00:00:00 2001 From: Eleanor Clifford Date: Thu, 30 Apr 2026 18:15:29 +0100 Subject: [PATCH] Pass backend tracebacks through to error pages --- utils/request.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/utils/request.js b/utils/request.js index 3b94c53..6f535db 100644 --- a/utils/request.js +++ b/utils/request.js @@ -2,12 +2,32 @@ // @ts-ignore const fetch = require("node-fetch") -function request(url, options = {}) { +async function request(url, options = {}) { if (!options.headers) options.headers = {} options.headers = { "user-agent": "CloudTubeBackend/1.0" } - return fetch(url, options) + const res = await fetch(url, options) + + if (res.status >= 400) { + if (res.status == 500) { + let body = await res.text(); + + const traceback_start = '
';
+			const traceback_end = '
'; + + const si = body.indexOf(traceback_start) + if (si >= 0) body = body.slice(si + traceback_start.length); + + const ei = body.indexOf(traceback_end) + if (ei >= 0) body = body.slice(0, ei); + + throw new Error(`Unexpected error in backend:\n\n${body}`); + } else { + throw new Error(`Unexpected response from backend: ${res.status} ${res.statusText}`); + } + } + return res } module.exports.request = request