diff --git a/src/lib/geoip/client.ts b/src/lib/geoip/client.ts index c0228281..95c6120a 100644 --- a/src/lib/geoip/client.ts +++ b/src/lib/geoip/client.ts @@ -2,7 +2,7 @@ import _ from 'lodash'; import config from 'config'; import newrelic from 'newrelic'; import type { CacheInterface } from '../cache/cache-interface.js'; -import { InternalError } from '../internal-error.js'; +import { ProbeError } from '../probe-error.js'; import type { ProbeLocation } from '../../probe/types.js'; import RedisCache from '../cache/redis-cache.js'; import { getRedisClient } from '../redis/client.js'; @@ -58,7 +58,7 @@ export default class GeoipClient { ); if (ip2location.status === 'fulfilled' && ip2location.value.isProxy && !isAddrWhitelisted(addr)) { - throw new InternalError('vpn detected', true); + throw new ProbeError('vpn detected'); } return fulfilled.filter(Boolean).flat(); @@ -67,14 +67,14 @@ export default class GeoipClient { const resultsWithCities = results.filter(s => s.city); if (resultsWithCities.length === 0 || (resultsWithCities.length === 1 && resultsWithCities[0]?.provider === 'fastly')) { - throw new InternalError(`unresolvable geoip: ${addr}`, true); + throw new ProbeError(`unresolvable geoip: ${addr}`); } const [ match, ranked ] = this.bestMatch('normalizedCity', results); const networkMatch = this.matchNetwork(match, ranked); if (!networkMatch) { - throw new InternalError(`unresolvable geoip: ${addr}`, true); + throw new ProbeError(`unresolvable geoip: ${addr}`); } const region = this.matchRegion(match); diff --git a/src/lib/internal-error.ts b/src/lib/internal-error.ts deleted file mode 100644 index 7210d745..00000000 --- a/src/lib/internal-error.ts +++ /dev/null @@ -1,9 +0,0 @@ -export class InternalError extends Error { - expose?: boolean; - - constructor (message: string, isExposed: boolean) { - super(message); - - this.expose = isExposed; - } -} diff --git a/src/lib/probe-error.ts b/src/lib/probe-error.ts new file mode 100644 index 00000000..5c696a43 --- /dev/null +++ b/src/lib/probe-error.ts @@ -0,0 +1 @@ +export class ProbeError extends Error {} diff --git a/src/lib/ws/helper/probe-ip-limit.ts b/src/lib/ws/helper/probe-ip-limit.ts index 0f5f7746..a9cc27b7 100644 --- a/src/lib/ws/helper/probe-ip-limit.ts +++ b/src/lib/ws/helper/probe-ip-limit.ts @@ -1,6 +1,6 @@ import { fetchSockets } from '../server.js'; import { scopedLogger } from '../../logger.js'; -import { InternalError } from '../../internal-error.js'; +import { ProbeError } from '../../probe-error.js'; import type { LRUOptions } from './throttle.js'; const logger = scopedLogger('ws:limit'); @@ -22,6 +22,6 @@ export const verifyIpLimit = async (ip: string, socketId: string): Promise if (previousSocket) { logger.info(`ws client ${socketId} has reached the concurrent IP limit.`, { message: previousSocket.data.probe.ipAddress }); - throw new InternalError('ip limit', true); + throw new ProbeError('ip limit'); } }; diff --git a/src/lib/ws/middleware/probe-metadata.ts b/src/lib/ws/middleware/probe-metadata.ts index de0fae47..b7f24268 100644 --- a/src/lib/ws/middleware/probe-metadata.ts +++ b/src/lib/ws/middleware/probe-metadata.ts @@ -2,7 +2,7 @@ import type { Socket } from 'socket.io'; import type { ExtendedError } from 'socket.io/dist/namespace.js'; import { WsError } from '../ws-error.js'; import { buildProbe } from '../../../probe/builder.js'; -import { InternalError } from '../../internal-error.js'; +import { ProbeError } from '../../probe-error.js'; import { errorHandler } from '../helper/error-handler.js'; import { scopedLogger } from '../../logger.js'; import getProbeIp from '../../get-probe-ip.js'; @@ -19,7 +19,7 @@ export const probeMetadata = errorHandler(async (socket: Socket, next: (error?: logger.error(error); let message = 'failed to collect probe metadata'; - if (error instanceof InternalError && error?.expose) { + if (error instanceof ProbeError) { message = error.message; } diff --git a/src/probe/builder.ts b/src/probe/builder.ts index fe08ad2c..7b2f891b 100644 --- a/src/probe/builder.ts +++ b/src/probe/builder.ts @@ -11,7 +11,7 @@ import { getContinentAliases, getRegionAliases, } from '../lib/location/location.js'; -import { InternalError } from '../lib/internal-error.js'; +import { ProbeError } from '../lib/probe-error.js'; import { createGeoipClient } from '../lib/geoip/client.js'; import getProbeIp from '../lib/get-probe-ip.js'; import { getRegion } from '../lib/ip-ranges.js'; @@ -35,7 +35,7 @@ export const buildProbe = async (socket: Socket): Promise => { } if (!semver.satisfies(version, '>=0.9.0')) { - throw new InternalError(`invalid probe version (${version})`, true); + throw new ProbeError(`invalid probe version (${version})`); } let ipInfo;