Giter VIP home page Giter VIP logo

Comments (11)

lentryd avatar lentryd commented on June 12, 2024

try catch может помочь.
А вообще все функции в библиотеке это промисы и у них ошибки ловятся с помощью .catch

В твоём случае можно сделать так.

const result = await user.reportFile({...}).catch(() => null);
if (result == null) console.log("Ошибка");

from netschoolapi.

lentryd avatar lentryd commented on June 12, 2024

Иногда на каком-то запросе происходит задержка

Можешь в ручную увеличить время параметра timeout (см. документацию)

from netschoolapi.

lentryd avatar lentryd commented on June 12, 2024

Как обработать неудачный запрос reportFile и сразу повторить с этого же места?

let result = null;

do {
  result = await user.reportFile({...}).catch(() => null);
} while (result == null);

только лучше еще добавить счетчик итераций, чтобы это не было бесконечно

from netschoolapi.

agran avatar agran commented on June 12, 2024

Не помогло, всё равно завершается с сообщением "DONE Сеанс ЛОГИН успешно закрыт".

from netschoolapi.

agran avatar agran commented on June 12, 2024

Вот пример моего кода, всё равно вылетает скрипт.

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.

lentryd avatar lentryd commented on June 12, 2024

Можешь ещё бахнуть try catch он 100% все отловить сможет, только тут уже нужно будет использовать рекурсию

from netschoolapi.

agran avatar agran commented on June 12, 2024
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.

lentryd avatar lentryd commented on June 12, 2024

А скинь скриншот ошибки, которая приводила к завершению кода

from netschoolapi.

agran avatar agran commented on June 12, 2024

Пока не попадалась.

from netschoolapi.

agran avatar agran commented on June 12, 2024
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.

agran avatar agran commented on June 12, 2024

Проблема в том что следующий код:

	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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.