Improve Lidarr error passthrough with endpoint and detailed 400 messages

This commit is contained in:
J0Z1L 2026-02-28 00:41:40 +01:00
parent 65adc453d4
commit 713e090c2c

View file

@ -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 });