mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
refactor: Improve error handling in FetchListAndProbe
This commit refactors the FetchListAndProbe class to improve error handling. It adds try-catch blocks around the main logic and logs any errors that occur using the logger. Additionally, it includes a catch block to handle any errors thrown during the fetchListAndProbe function. This change ensures that errors are properly handled and logged, preventing potential issues with the monitoring process.
This commit is contained in:
parent
0e53e26695
commit
cc3f003be5
@ -322,7 +322,9 @@ export default class API {
|
||||
// get url from error
|
||||
const url: string = error?.config?.url || "";
|
||||
|
||||
throw new APIException(`URL ${url ? url + " " : ""}is not available.`);
|
||||
throw new APIException(`
|
||||
Error occurred while making request to ${url}. ${error.message}
|
||||
`);
|
||||
}
|
||||
|
||||
public static getFriendlyErrorMessage(error: AxiosError | Error): string {
|
||||
|
@ -26,20 +26,29 @@ export default class FetchListAndProbe {
|
||||
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const runTime: Date = OneUptimeDate.getCurrentDate();
|
||||
try {
|
||||
const runTime: Date = OneUptimeDate.getCurrentDate();
|
||||
|
||||
logger.debug(`Probing monitors ${this.workerName}`);
|
||||
logger.debug(`Probing monitors ${this.workerName}`);
|
||||
|
||||
await this.fetchListAndProbe();
|
||||
await this.fetchListAndProbe();
|
||||
|
||||
logger.debug(`Probing monitors ${this.workerName} complete`);
|
||||
logger.debug(`Probing monitors ${this.workerName} complete`);
|
||||
|
||||
// if rumTime + 5 seconds is in the future, then this fetchLst either errored out or had no monitors in the list. Either way, wait for 5 seconds and proceed.
|
||||
// if rumTime + 5 seconds is in the future, then this fetchLst either errored out or had no monitors in the list. Either way, wait for 5 seconds and proceed.
|
||||
|
||||
const twoSecondsAdded: Date = OneUptimeDate.addRemoveSeconds(runTime, 2);
|
||||
const twoSecondsAdded: Date = OneUptimeDate.addRemoveSeconds(
|
||||
runTime,
|
||||
2,
|
||||
);
|
||||
|
||||
if (OneUptimeDate.isInTheFuture(twoSecondsAdded)) {
|
||||
logger.debug(`Worker ${this.workerName} is waiting for 2 seconds`);
|
||||
if (OneUptimeDate.isInTheFuture(twoSecondsAdded)) {
|
||||
logger.debug(`Worker ${this.workerName} is waiting for 2 seconds`);
|
||||
await Sleep.sleep(2000);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(`Error in worker ${this.workerName}`);
|
||||
logger.error(err);
|
||||
await Sleep.sleep(2000);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user