Skip to content

Commit

Permalink
refactor: rename internal error to probe error (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh authored Sep 11, 2023
1 parent 36ee06c commit 3121388
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/lib/geoip/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
9 changes: 0 additions & 9 deletions src/lib/internal-error.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/lib/probe-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class ProbeError extends Error {}
4 changes: 2 additions & 2 deletions src/lib/ws/helper/probe-ip-limit.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -22,6 +22,6 @@ export const verifyIpLimit = async (ip: string, socketId: string): Promise<void>

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');
}
};
4 changes: 2 additions & 2 deletions src/lib/ws/middleware/probe-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/probe/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -35,7 +35,7 @@ export const buildProbe = async (socket: Socket): Promise<Probe> => {
}

if (!semver.satisfies(version, '>=0.9.0')) {
throw new InternalError(`invalid probe version (${version})`, true);
throw new ProbeError(`invalid probe version (${version})`);
}

let ipInfo;
Expand Down

0 comments on commit 3121388

Please sign in to comment.