From 713e090c2caf293fecdace9e803b3990f3487e29 Mon Sep 17 00:00:00 2001 From: J0Z1L Date: Sat, 28 Feb 2026 00:41:40 +0100 Subject: [PATCH] Improve Lidarr error passthrough with endpoint and detailed 400 messages --- server.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/server.js b/server.js index 7972918..2439dde 100644 --- a/server.js +++ b/server.js @@ -182,17 +182,28 @@ async function lidarrRequest(method, endpoint, data, params) { if (!hasLidarrConfig()) { throw new Error('Lidarr-Konfiguration unvollstaendig.'); } - - const response = await axios({ - method, - url: `${lidarrUrl}${endpoint}`, - headers: lidarrHeaders(), - data, - params, - timeout: 20000 - }); - - return response.data; + try { + const response = await axios({ + method, + url: `${lidarrUrl}${endpoint}`, + headers: lidarrHeaders(), + data, + params, + timeout: 20000 + }); + return response.data; + } catch (err) { + const status = err.response?.status || 500; + const body = err.response?.data; + const detail = + body?.message || + body?.error || + (Array.isArray(body) ? JSON.stringify(body) : typeof body === 'string' ? body : '') || + err.message; + const wrapped = new Error(`Lidarr API ${method.toUpperCase()} ${endpoint} -> ${detail}`); + wrapped.status = status; + throw wrapped; + } } async function getSpotifyToken() { @@ -796,7 +807,7 @@ app.post('/api/lidarr/send-album', async (req, res) => { const result = await processSendAlbum(req.body || {}); res.json(result); } catch (err) { - res.status(500).json({ error: err.message }); + res.status(err.status || 500).json({ error: err.message }); } }); @@ -810,7 +821,7 @@ app.post('/api/lidarr/send-batch', async (req, res) => { const result = await processSendAlbum(item); results.push({ ok: true, result }); } catch (err) { - results.push({ ok: false, error: err.message, item }); + results.push({ ok: false, status: err.status || 500, error: err.message, item }); } } res.json({ success: true, results });