Обработка ошибок Aspiration
This commit is contained in:
parent
28fdd04fbe
commit
6c1957bdce
@ -1,4 +1,5 @@
|
||||
import requests
|
||||
from sabron.util import logging
|
||||
from sabron.util.sabronmodule import get_settings
|
||||
|
||||
|
||||
@ -7,8 +8,11 @@ class AspirationUnitAPI:
|
||||
self.api_host = get_settings('api_host')
|
||||
|
||||
def get_aspiration_unit_by_id(self, id: int):
|
||||
response = requests.get(f'{self.api_host}/api/v2/scada/sensor/{id}')
|
||||
response.raise_for_status()
|
||||
try:
|
||||
response = requests.get(f'{self.api_host}/api/v2/scada/sensor/{id}', timeout=1)
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return {}
|
||||
data = response.json()['responce']
|
||||
return {
|
||||
'name': data['name'],
|
||||
|
||||
@ -12,5 +12,6 @@ class AspirationService(DashboardBaseService):
|
||||
res = []
|
||||
for id_ in qs:
|
||||
asp_unit = api.get_aspiration_unit_by_id(id=id_)
|
||||
res.append(asp_unit)
|
||||
if asp_unit:
|
||||
res.append(asp_unit)
|
||||
return res
|
||||
|
||||
@ -73,11 +73,16 @@
|
||||
}
|
||||
const json = await response.json();
|
||||
|
||||
const data = json['data']
|
||||
|
||||
// Очистка контейнера перед добавлением новых элементов
|
||||
aspiration_container.innerHTML = '';
|
||||
|
||||
if (data.length === 0) {
|
||||
aspiration_container.innerHTML = `<h1>Нет данных</h1>`
|
||||
}
|
||||
// Добавление новых элементов
|
||||
for (let item of json['data']) {
|
||||
for (let item of data) {
|
||||
const card = createAspirationCard(item);
|
||||
aspiration_container.appendChild(card);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user