diff --git a/Common/Types/Exception/ApiException.ts b/Common/Types/Exception/ApiException.ts index 80529336270..e41fbfd8134 100644 --- a/Common/Types/Exception/ApiException.ts +++ b/Common/Types/Exception/ApiException.ts @@ -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; + } } } diff --git a/Common/Utils/API.ts b/Common/Utils/API.ts index 6bb38f95b9e..a388f567189 100644 --- a/Common/Utils/API.ts +++ b/Common/Utils/API.ts @@ -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 { diff --git a/Ingestor/API/Monitor.ts b/Ingestor/API/Monitor.ts index 10581b129e3..efa9b381fcb 100644 --- a/Ingestor/API/Monitor.ts +++ b/Ingestor/API/Monitor.ts @@ -340,6 +340,7 @@ router.post( // return the list of monitors to be monitored + logger.debug("Sending response"); return Response.sendEntityArrayResponse( req, res, diff --git a/Probe/Jobs/Monitor/FetchList.ts b/Probe/Jobs/Monitor/FetchList.ts index e71d0cb5da7..3bddfb4ff66 100644 --- a/Probe/Jobs/Monitor/FetchList.ts +++ b/Probe/Jobs/Monitor/FetchList.ts @@ -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)); + } } } }