Fixed timeout issue

This commit is contained in:
Selim Mustafaev 2024-10-12 08:02:56 +00:00
parent 105bd25dc2
commit d42ec39038
4 changed files with 9 additions and 22 deletions

View File

@ -141,6 +141,7 @@ class AvtocodProvider {
console.log('Avtocod found vehicle: ', vehicle?.brand?.name?.original); console.log('Avtocod found vehicle: ', vehicle?.brand?.name?.original);
return vehicle; return vehicle;
} catch(ex) { } catch(ex) {
console.log('Avtocod error: ', ex.message);
ex.debugInfo = { autocod: DebugInfo.fromError(ex.message) }; ex.debugInfo = { autocod: DebugInfo.fromError(ex.message) };
throw ex; throw ex;
} }

View File

@ -20,11 +20,10 @@ class NomerogramProvider {
let hash = createHash("sha256"); let hash = createHash("sha256");
hash.update(secretSource); hash.update(secretSource);
let secret = hash.digest("hex"); let secret = hash.digest("hex");
console.log("secret: ", secret);
let url = `${baseUrl}/group/list?from=${from}&carplate=${number}&timestamp=${timestamp}&secret=${secret}&app_id=${appId}&device_id=${deviceId}`; let url = `${baseUrl}/group/list?from=${from}&carplate=${number}&timestamp=${timestamp}&secret=${secret}&app_id=${appId}&device_id=${deviceId}`;
let result = await fetch(url, { let result = await fetch(url, {
timeout: 5000, signal: AbortSignal.timeout(5000),
headers: { "User-Agent": userAgent }, headers: { "User-Agent": userAgent },
}); });
let json = await result.json(); let json = await result.json();

View File

@ -3,33 +3,18 @@ import DebugInfo from '../models/DebugInfo.js';
import Vehicle from '../models/vehicle.js'; import Vehicle from '../models/vehicle.js';
import Utils from '../utils/utils.js'; import Utils from '../utils/utils.js';
const baseUrl = 'https://vin01.ru/v2'; const baseUrl = 'https://vin-01.ru/v2';
const reportBaseUrl = `${baseUrl}/gibddApp.php`; const reportBaseUrl = `${baseUrl}/gibddApp.php`;
async function fetchWithTimeout(url, params, timeout) {
const controller = new AbortController();
const timeoutId = setTimeout(() => {
controller.abort();
}, timeout);
let requestParams = params ?? {};
requestParams.signal = controller.signal;
try {
return await fetch(url, requestParams);
} finally {
clearInterval(timeoutId);
}
}
class Vin01Provider { class Vin01Provider {
static async getVin(number, token) { static async getVin(number, token) {
let url = `${baseUrl}/getVin.php?key=${token}&gosNumber=${encodeURIComponent(number)}`; let url = `${baseUrl}/getVin.php?key=${token}&gosNumber=${encodeURIComponent(number)}`;
let result = await fetchWithTimeout(url, null, 14000); let result = await fetch(url, { signal: AbortSignal.timeout(14000) });
let json = await result.json(); let json = await result.json();
if(json.success && json.code == 200) { if(json.success && json.code == 200) {
return json.data.vin; return json.data.vin;
} else { } else {
console.log('Vin01 provider failed to get VIN');
throw Error('Vin01 provider failed to get VIN'); throw Error('Vin01 provider failed to get VIN');
} }
} }
@ -77,6 +62,7 @@ class Vin01Provider {
console.log('vin01 found VIN: ', vin); console.log('vin01 found VIN: ', vin);
return await this.getReportVin(vin, number, token); return await this.getReportVin(vin, number, token);
} catch(ex) { } catch(ex) {
console.log('Vin01 error: ', ex.message);
ex.debugInfo = { ex.debugInfo = {
vin01vin:DebugInfo.fromError(ex.message), vin01vin:DebugInfo.fromError(ex.message),
vin01history: DebugInfo.fromError('Not applicable (VIN was not found)'), vin01history: DebugInfo.fromError('Not applicable (VIN was not found)'),

View File

@ -9,6 +9,7 @@ module.exports = {
autorestart: true, autorestart: true,
watch: false, watch: false,
max_memory_restart: '1G', max_memory_restart: '1G',
log_date_format: 'YYYY-MM-DD HH:mm:ss',
env: { env: {
NODE_ENV: 'development' NODE_ENV: 'development'
}, },