CEC-287, CEC-279 Fix car connections and add logger (#61)

* Display cars if connection statuses call errors

* Fix connection error
Add logger
This commit is contained in:
John Wu
2021-06-23 16:33:35 -07:00
committed by GitHub
parent a3b6b01bf3
commit f4e4261d01
4 changed files with 170 additions and 113 deletions

View File

@@ -1,4 +1,5 @@
import React, { useContext, useState } from "react";
import { logger } from "../../services/monitoring";
import api from "../../services/vehicles";
const VehicleContext = React.createContext();
@@ -97,15 +98,19 @@ export const VehicleProvider = ({ children }) => {
};
const addConnections = async (cars, token) => {
const vins = cars.map((car) => car.vin);
const result = await api.getConnections(vins, token);
try {
const vins = cars.map((car) => car.vin);
const result = await api.getConnections(vins, token);
if (result.error) {
throw new Error(`Get connections error. ${result.message}`);
if (result.error) {
throw new Error(`Get connections error. ${result.message}`);
}
cars.forEach((car) => {
car.connected = result[car.vin] || false;
});
} catch (e) {
logger.error(e.stack);
}
cars.forEach((car) => {
car.connected = result[car.vin] || false;
});
};
const getConnections = async (vins, token) => {