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
9b862162b6
commit
de7d06e5d7
@ -2,7 +2,18 @@ import Exception from "./Exception";
|
||||
import ExceptionCode from "./ExceptionCode";
|
||||
|
||||
export default class APIException extends Exception {
|
||||
public constructor(message: string) {
|
||||
private _error: Error | null = null;
|
||||
public get error(): Error | null {
|
||||
return this._error || null;
|
||||
}
|
||||
public set error(v: Error | null) {
|
||||
this._error = v;
|
||||
}
|
||||
|
||||
public constructor(message: string, error?: Error) {
|
||||
super(ExceptionCode.APIException, message);
|
||||
if (error) {
|
||||
this.error = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,9 +322,10 @@ export default class API {
|
||||
// get url from error
|
||||
const url: string = error?.config?.url || "";
|
||||
|
||||
throw new APIException(`
|
||||
Error occurred while making request to ${url}. ${error.message}
|
||||
`);
|
||||
throw new APIException(
|
||||
`Error occurred while making request to ${url}.`,
|
||||
error,
|
||||
);
|
||||
}
|
||||
|
||||
public static getFriendlyErrorMessage(error: AxiosError | Error): string {
|
||||
|
@ -340,6 +340,7 @@ router.post(
|
||||
|
||||
// return the list of monitors to be monitored
|
||||
|
||||
logger.debug("Sending response");
|
||||
return Response.sendEntityArrayResponse(
|
||||
req,
|
||||
res,
|
||||
|
@ -7,6 +7,7 @@ import HTTPMethod from "Common/Types/API/HTTPMethod";
|
||||
import HTTPResponse from "Common/Types/API/HTTPResponse";
|
||||
import URL from "Common/Types/API/URL";
|
||||
import OneUptimeDate from "Common/Types/Date";
|
||||
import APIException from "Common/Types/Exception/ApiException";
|
||||
import { JSONArray } from "Common/Types/JSON";
|
||||
import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse";
|
||||
import Sleep from "Common/Types/Sleep";
|
||||
@ -116,6 +117,11 @@ export default class FetchListAndProbe {
|
||||
} catch (err) {
|
||||
logger.error("Error in fetching monitor list");
|
||||
logger.error(err);
|
||||
|
||||
if (err instanceof APIException) {
|
||||
logger.error("API Exception Error");
|
||||
logger.error(JSON.stringify(err.error, null, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user