Improve Lidarr error passthrough with endpoint and detailed 400 messages
This commit is contained in:
parent
65adc453d4
commit
713e090c2c
1 changed files with 24 additions and 13 deletions
37
server.js
37
server.js
|
|
@ -182,17 +182,28 @@ async function lidarrRequest(method, endpoint, data, params) {
|
||||||
if (!hasLidarrConfig()) {
|
if (!hasLidarrConfig()) {
|
||||||
throw new Error('Lidarr-Konfiguration unvollstaendig.');
|
throw new Error('Lidarr-Konfiguration unvollstaendig.');
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
const response = await axios({
|
const response = await axios({
|
||||||
method,
|
method,
|
||||||
url: `${lidarrUrl}${endpoint}`,
|
url: `${lidarrUrl}${endpoint}`,
|
||||||
headers: lidarrHeaders(),
|
headers: lidarrHeaders(),
|
||||||
data,
|
data,
|
||||||
params,
|
params,
|
||||||
timeout: 20000
|
timeout: 20000
|
||||||
});
|
});
|
||||||
|
return response.data;
|
||||||
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() {
|
async function getSpotifyToken() {
|
||||||
|
|
@ -796,7 +807,7 @@ app.post('/api/lidarr/send-album', async (req, res) => {
|
||||||
const result = await processSendAlbum(req.body || {});
|
const result = await processSendAlbum(req.body || {});
|
||||||
res.json(result);
|
res.json(result);
|
||||||
} catch (err) {
|
} 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);
|
const result = await processSendAlbum(item);
|
||||||
results.push({ ok: true, result });
|
results.push({ ok: true, result });
|
||||||
} catch (err) {
|
} 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 });
|
res.json({ success: true, results });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue