Add warnings to debugInfo
This commit is contained in:
parent
3ea920d169
commit
0194f3472b
@ -2,7 +2,7 @@ const crypto = require('crypto');
|
||||
const fetch = require('node-fetch');
|
||||
const Vehicle = require('../models/vehicle');
|
||||
const PubNub = require('pubnub');
|
||||
const { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } = require('constants');
|
||||
const DebugInfo = require('../models/DebugInfo');
|
||||
|
||||
const baseUrl = 'https://avtocod.ru/api/v3';
|
||||
let deviceToken = crypto.createHash('sha256').update(Date.now().toString()).digest().toString('hex');
|
||||
@ -99,12 +99,7 @@ class AvtocodProvider {
|
||||
console.log('Avtocod found vehicle: ', vehicle?.brand?.name?.original);
|
||||
return vehicle;
|
||||
} catch(ex) {
|
||||
ex.debugInfo = {
|
||||
autocod: {
|
||||
fields: 0,
|
||||
error: ex.message
|
||||
}
|
||||
}
|
||||
ex.debugInfo = { autocod: DebugInfo.fromError(ex.message) };
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ const crypto = require('crypto');
|
||||
const fetch = require('node-fetch');
|
||||
const Utils = require('../utils');
|
||||
const utf8 = require('utf8');
|
||||
const DebugInfo = require('../models/DebugInfo');
|
||||
|
||||
const baseUrl = 'https://www.nomerogram.ru/api/v1.1';
|
||||
|
||||
@ -51,7 +52,7 @@ class NomerogramProvider {
|
||||
});
|
||||
} catch(ex) {
|
||||
console.log('Nomerogram error: ', ex.message);
|
||||
ex.debugInfo = { nomerogram: { fields: 0, error: ex.message } };
|
||||
ex.debugInfo = { nomerogram: DebugInfo.fromError(ex.message) };
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
const fetch = require('node-fetch');
|
||||
const DebugInfo = require('../models/DebugInfo');
|
||||
const Vehicle = require('../models/vehicle');
|
||||
const Utils = require('../utils');
|
||||
|
||||
@ -67,9 +68,9 @@ class Vin01Provider {
|
||||
let vehicle = new Vehicle();
|
||||
vehicle.vin1 = Utils.cyrillicToLatin(vin);
|
||||
vehicle.debugInfo = {
|
||||
vin01vin: { fields: 0, error: null },
|
||||
vin01history: { fields: 0, error: history.reason.message },
|
||||
vin01base: { fields: 0, error: base.reason.message }
|
||||
vin01vin: new DebugInfo(),
|
||||
vin01history: DebugInfo.fromError(history.reason.message),
|
||||
vin01base: DebugInfo.fromError(base.reason.message)
|
||||
};
|
||||
return vehicle;
|
||||
} else if(base.status == 'rejected') {
|
||||
@ -77,8 +78,8 @@ class Vin01Provider {
|
||||
let vehicle = Vehicle.fromVin01History(history.value);
|
||||
vehicle.number = number;
|
||||
Object.assign(vehicle.debugInfo, {
|
||||
vin01vin: { fields: 0, error: null },
|
||||
vin01base: { fields: 0, error: base.reason.message }
|
||||
vin01vin: new DebugInfo(),
|
||||
vin01base: DebugInfo.fromError(base.reason.message)
|
||||
});
|
||||
return vehicle;
|
||||
} else if(history.status == 'rejected') {
|
||||
@ -86,8 +87,8 @@ class Vin01Provider {
|
||||
let vehicle = Vehicle.fromVin01Base(base.value);
|
||||
vehicle.number = number;
|
||||
Object.assign(vehicle.debugInfo, {
|
||||
vin01vin: { fields: 0, error: null },
|
||||
vin01history: { fields: 0, error: history.reason.message }
|
||||
vin01vin: new DebugInfo(),
|
||||
vin01history: DebugInfo.fromError(history.reason.message)
|
||||
});
|
||||
return vehicle;
|
||||
} else {
|
||||
@ -123,7 +124,7 @@ class Vin01Provider {
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(historyVehicle.debugInfo, { vin01vin: { fields: 0, error: null } });
|
||||
Object.assign(historyVehicle.debugInfo, { vin01vin: new DebugInfo() });
|
||||
Object.assign(historyVehicle.debugInfo, baseVehicle.debugInfo);
|
||||
|
||||
historyVehicle.number = number;
|
||||
@ -131,9 +132,9 @@ class Vin01Provider {
|
||||
}
|
||||
} catch(ex) {
|
||||
ex.debugInfo = {
|
||||
vin01vin: { fields: 0, error: ex.message },
|
||||
vin01history: { fields: 0, error: 'Not applicable (VIN was not found)' },
|
||||
vin01base: { fields: 0, error: 'Not applicable (VIN was not found)' }
|
||||
vin01vin: DebugInfo.fromError(ex.message),
|
||||
vin01history: DebugInfo.fromError('Not applicable (VIN was not found)'),
|
||||
vin01base: DebugInfo.fromError('Not applicable (VIN was not found)')
|
||||
};
|
||||
throw ex;
|
||||
}
|
||||
|
||||
32
models/DebugInfo.js
Normal file
32
models/DebugInfo.js
Normal file
@ -0,0 +1,32 @@
|
||||
class DebugInfo {
|
||||
status
|
||||
fields
|
||||
error
|
||||
|
||||
constructor() {
|
||||
this.status = 0;
|
||||
this.fields = 0;
|
||||
this.error = null;
|
||||
}
|
||||
|
||||
static fromError(error) {
|
||||
let di = new DebugInfo();
|
||||
di.status = 1;
|
||||
di.error = error;
|
||||
return di;
|
||||
}
|
||||
|
||||
static fromWarning(warning) {
|
||||
let di = new DebugInfo();
|
||||
di.status = 2;
|
||||
di.error = warning;
|
||||
return di;
|
||||
}
|
||||
|
||||
setWarning(warning) {
|
||||
this.status = 2;
|
||||
this.error = warning;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DebugInfo;
|
||||
@ -1,5 +1,6 @@
|
||||
const Constants = require('../data_providers/constants');
|
||||
const Utils = require('../utils');
|
||||
const DebugInfo = require('./DebugInfo');
|
||||
|
||||
class Vehicle {
|
||||
brand
|
||||
@ -61,13 +62,7 @@ class Vehicle {
|
||||
v.addedDate = Date.now();
|
||||
v.updatedDate = v.addedDate;
|
||||
v.events = [];
|
||||
|
||||
v.debugInfo = {
|
||||
autocod: {
|
||||
fields: 0,
|
||||
error: null
|
||||
}
|
||||
};
|
||||
v.debugInfo = { autocod: new DebugInfo() };
|
||||
|
||||
return v;
|
||||
}
|
||||
@ -105,13 +100,7 @@ class Vehicle {
|
||||
v.addedDate = Date.now();
|
||||
v.updatedDate = v.addedDate;
|
||||
v.events = [];
|
||||
|
||||
v.debugInfo = {
|
||||
vin01history: {
|
||||
fields: 0,
|
||||
error: null
|
||||
}
|
||||
};
|
||||
v.debugInfo = { vin01history: new DebugInfo() };
|
||||
|
||||
return v;
|
||||
}
|
||||
@ -167,13 +156,7 @@ class Vehicle {
|
||||
v.addedDate = Date.now();
|
||||
v.updatedDate = v.addedDate;
|
||||
v.events = [];
|
||||
|
||||
v.debugInfo = {
|
||||
vin01base: {
|
||||
fields: 0,
|
||||
error: null
|
||||
}
|
||||
};
|
||||
v.debugInfo = { vin01base: new DebugInfo() };
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ const RsaProvider = require('../data_providers/rsa');
|
||||
const NomerogramProvider = require('../data_providers/nomerogram');
|
||||
const Utils = require('../utils');
|
||||
const ObjectId = require('mongodb').ObjectID;
|
||||
const DebugInfo = require('../models/DebugInfo');
|
||||
|
||||
const makeError = error => ({ success: false, error });
|
||||
|
||||
@ -39,9 +40,9 @@ router.post('/check', async (req, res) => {
|
||||
} else {
|
||||
all.push(Promise.reject({
|
||||
debugInfo: {
|
||||
vin01vin: { fields: 0, error: 'No auth token' },
|
||||
vin01history: { fields: 0, error: 'No auth token' },
|
||||
vin01base: { fields: 0, error: 'No auth token' }
|
||||
vin01vin: DebugInfo.fromError('No auth token'),
|
||||
vin01history: DebugInfo.fromError('No auth token'),
|
||||
vin01base: DebugInfo.fromError('No auth token')
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -64,18 +65,26 @@ router.post('/check', async (req, res) => {
|
||||
}
|
||||
} else {
|
||||
vehicle = autocod.value;
|
||||
if(vehicle.vin1 && vin01.value.vin1.match(RegExp(vehicle.vin1.replace(/\*/g, '.')))) {
|
||||
let vinMatch = vin01.value.vin1.match(RegExp(vehicle.vin1.replace(/\*/g, '.')));
|
||||
if(vehicle.vin1 && vinMatch) {
|
||||
vehicle.vin1 = vin01.value.vin1;
|
||||
vehicle.vin2 = vin01.value.vin2;
|
||||
vehicle.color = vin01.value.color;
|
||||
vehicle.ownershipPeriods = vin01.value.ownershipPeriods;
|
||||
} else if(!vinMatch) {
|
||||
let vin01data = `${vin01.value.vin1} - ${vin01.value.brand.name.original}`;
|
||||
let autocodData = `${autocod.value.vin1} - ${autocod.value.brand.name.original}`;
|
||||
let warning = `Vin01 VIN (${vin01data}) doesn't match with avtocod's one (${autocodData})`;
|
||||
vin01.value.debugInfo.vin01vin.setWarning(warning);
|
||||
vin01.value.debugInfo.vin01history.setWarning(warning);
|
||||
vin01.value.debugInfo.vin01base.setWarning(warning);
|
||||
}
|
||||
Object.assign(vehicle.debugInfo, vin01.value.debugInfo);
|
||||
}
|
||||
|
||||
if(nomerogram.status == 'fulfilled') {
|
||||
vehicle.ads = nomerogram.value;
|
||||
Object.assign(vehicle.debugInfo, { nomerogram: { fields: 0, error: null } });
|
||||
Object.assign(vehicle.debugInfo, { nomerogram: new DebugInfo() });
|
||||
} else {
|
||||
Object.assign(vehicle.debugInfo, nomerogram.reason.debugInfo);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user