correct return types
This commit is contained in:
1 parent
bfa11216f0
commit
a0ea50d745
1 file changed
+16
-9
@@ -1,6 +1,13 @@
|
|||||||
import { HTTPError, RequestError } from "got";
|
import { HTTPError, RequestError } from "got";
|
||||||
import type { Got, Response } from "got";
|
import type { Got, Response } from "got";
|
||||||
import type { Monitor, MonitorStatusResponse, GrpcStatusPayload } from "@/types/index.js";
|
import type {
|
||||||
|
Monitor,
|
||||||
|
MonitorStatusResponse,
|
||||||
|
GrpcStatusPayload,
|
||||||
|
PageSpeedStatusPayload,
|
||||||
|
HttpStatusPayload,
|
||||||
|
HardwareStatusPayload,
|
||||||
|
} from "@/types/index.js";
|
||||||
import type { AxiosStatic } from "axios";
|
import type { AxiosStatic } from "axios";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
@@ -192,7 +199,7 @@ class NetworkService implements INetworkService {
|
|||||||
case this.TYPE_PING:
|
case this.TYPE_PING:
|
||||||
return await this.requestPing(monitor);
|
return await this.requestPing(monitor);
|
||||||
case this.TYPE_HTTP:
|
case this.TYPE_HTTP:
|
||||||
return await this.requestHttp(monitor);
|
return await this.requestHttp<HttpStatusPayload>(monitor);
|
||||||
case this.TYPE_PAGESPEED:
|
case this.TYPE_PAGESPEED:
|
||||||
return await this.requestPageSpeed(monitor);
|
return await this.requestPageSpeed(monitor);
|
||||||
case this.TYPE_HARDWARE:
|
case this.TYPE_HARDWARE:
|
||||||
@@ -257,9 +264,9 @@ class NetworkService implements INetworkService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async requestHttp(monitor: Monitor): Promise<MonitorStatusResponse> {
|
private async requestHttp<T = unknown>(monitor: Monitor): Promise<MonitorStatusResponse<T>> {
|
||||||
const { url, secret, id, teamId, type, ignoreTlsErrors, useAdvancedMatching, jsonPath, matchMethod, expectedValue } = monitor;
|
const { url, secret, ignoreTlsErrors, useAdvancedMatching, jsonPath, matchMethod, expectedValue } = monitor;
|
||||||
const httpResponse = this.buildStatusResponse({
|
const httpResponse = this.buildStatusResponse<T>({
|
||||||
monitor,
|
monitor,
|
||||||
overrides: {
|
overrides: {
|
||||||
status: false,
|
status: false,
|
||||||
@@ -390,7 +397,7 @@ class NetworkService implements INetworkService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async requestPageSpeed(monitor: Monitor): Promise<MonitorStatusResponse> {
|
private async requestPageSpeed(monitor: Monitor): Promise<MonitorStatusResponse<PageSpeedStatusPayload>> {
|
||||||
try {
|
try {
|
||||||
const url = monitor.url;
|
const url = monitor.url;
|
||||||
if (!url) {
|
if (!url) {
|
||||||
@@ -408,7 +415,7 @@ class NetworkService implements INetworkService {
|
|||||||
details: { url },
|
details: { url },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return await this.requestHttp({
|
return await this.requestHttp<PageSpeedStatusPayload>({
|
||||||
...monitor,
|
...monitor,
|
||||||
url: pageSpeedUrl,
|
url: pageSpeedUrl,
|
||||||
});
|
});
|
||||||
@@ -419,9 +426,9 @@ class NetworkService implements INetworkService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async requestHardware(monitor: Monitor): Promise<MonitorStatusResponse> {
|
private async requestHardware(monitor: Monitor): Promise<MonitorStatusResponse<HardwareStatusPayload>> {
|
||||||
try {
|
try {
|
||||||
return await this.requestHttp(monitor);
|
return await this.requestHttp<HardwareStatusPayload>(monitor);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
err.service = this.SERVICE_NAME;
|
err.service = this.SERVICE_NAME;
|
||||||
err.method = "requestHardware";
|
err.method = "requestHardware";
|
||||||
|
|||||||
Reference in new issue
Block a user