Comments (11)
try catch может помочь.
А вообще все функции в библиотеке это промисы и у них ошибки ловятся с помощью .catch
В твоём случае можно сделать так.
const result = await user.reportFile({...}).catch(() => null);
if (result == null) console.log("Ошибка");
from netschoolapi.
Иногда на каком-то запросе происходит задержка
Можешь в ручную увеличить время параметра timeout (см. документацию)
from netschoolapi.
Как обработать неудачный запрос reportFile и сразу повторить с этого же места?
let result = null;
do {
result = await user.reportFile({...}).catch(() => null);
} while (result == null);
только лучше еще добавить счетчик итераций, чтобы это не было бесконечно
from netschoolapi.
Не помогло, всё равно завершается с сообщением "DONE Сеанс ЛОГИН успешно закрыт".
from netschoolapi.
Вот пример моего кода, всё равно вылетает скрипт.
var result = null;
var col = 0;
do {
console.log("reports/studenttotal/queue " + col);
result = await user.reportFile({
url: "reports/studenttotal/queue",
filters: [{
filterId: "PCLID",
filterValue: klassid, // ID класса
},
{
filterId: "SEPTYPE",
filterValue: "0", // ID класса
},
{
filterId: "period",
filterValue: period,
},
],
}).catch(() => null);
col++;
if (col > 1) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
} while (result == null && col < 25);
from netschoolapi.
Можешь ещё бахнуть try catch он 100% все отловить сможет, только тут уже нужно будет использовать рекурсию
from netschoolapi.
var result = null;
var col = 0;
do {
console.log("reports/studenttotal/queue " + col);
try {
result = await user.reportFile({
url: "reports/studenttotal/queue",
filters: [{
filterId: "PCLID",
filterValue: klassid, // ID класса
},
{
filterId: "SEPTYPE",
filterValue: "0", // ID класса
},
{
filterId: "period",
filterValue: period,
},
],
timeout: 120000,
}).catch(() => null);
} catch (err) {
console.log(JSON.stringify(err));
result = null;
}
col++;
if (col > 1) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
} while (result == null && col < 25);
Посмотрю как этот код будет работать. Пока нормально.
from netschoolapi.
А скинь скриншот ошибки, которая приводила к завершению кода
from netschoolapi.
Пока не попадалась.
from netschoolapi.
const { inspect } = require('util');
var parents = null;
do {
try {
parents = await user
.fetch("/webapi/userinfo/"+uchenikId+"/parents")
.then((res) => res.json());
} catch (err) {
console.log(inspect(err, { showHidden: true }));
await new Promise(resolve => setTimeout(resolve, 10000));
}
} while (parents !== null);
Таким кодом делаю повторные запросы, так как сервер иногда возвращает 503 ошибку.
from netschoolapi.
Проблема в том что следующий код:
try {
result = await user.reportFile({
url: "reports/studenttotal/queue",
filters: [
{
filterId: "PCLID",
filterValue: klassid, // ID класса
},
{
filterId: "SEPTYPE",
filterValue: "0",
},
{
filterId: "period",
filterValue: period,
},
],
timeout: 5000
});
} catch (err) {
console.log(inspect(err, { showHidden: true }));
result = null;
}
Не отлавливает ошибку, а скрипт просто без всяких сообщений прекращает работу с случае если сервер что-то не то ответил. А хотелось бы в случае ошибки сервера попробовать сделать повторных запрос.
from netschoolapi.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from netschoolapi.