mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2026-05-26 04:22:25 +00:00
Pass backend tracebacks through to error pages
This commit is contained in:
parent
be33a66e8c
commit
a488052573
1 changed files with 22 additions and 2 deletions
|
|
@ -2,12 +2,32 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const fetch = require("node-fetch")
|
const fetch = require("node-fetch")
|
||||||
|
|
||||||
function request(url, options = {}) {
|
async function request(url, options = {}) {
|
||||||
if (!options.headers) options.headers = {}
|
if (!options.headers) options.headers = {}
|
||||||
options.headers = {
|
options.headers = {
|
||||||
"user-agent": "CloudTubeBackend/1.0"
|
"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 = '<pre id="traceback">';
|
||||||
|
const traceback_end = '</pre>';
|
||||||
|
|
||||||
|
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
|
module.exports.request = request
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue