adding fetch in try to prevent crashes

This commit is contained in:
Marek Maslowski
2026-04-04 22:43:13 +02:00
parent 3413d3f77d
commit c39ae2b965

View File

@@ -140,21 +140,26 @@ async function _fetchSynologyJson<T>(url: string, body: URLSearchParams): Promis
if (!SsrfResult.allowed) {
return fail(SsrfResult.error, 400);
}
const resp = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body,
signal: AbortSignal.timeout(30000),
});
if (!resp.ok) {
return fail('Synology API request failed with status ' + resp.status, resp.status);
try {
const resp = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body,
signal: AbortSignal.timeout(30000),
});
if (!resp.ok) {
return fail('Synology API request failed with status ' + resp.status, resp.status);
}
const response = await resp.json() as SynologyApiResponse<T>;
return response.success ? success(response.data) : fail('Synology failed with code ' + response.error.code, response.error.code);
}
catch {
return fail('Failed to connect to Synology API', 500);
}
const response = await resp.json() as SynologyApiResponse<T>;
return response.success ? success(response.data) : fail('Synology failed with code ' + response.error.code, response.error.code);
}
async function _loginToSynology(url: string, username: string, password: string): Promise<ServiceResult<string>> {