-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add: support api:connect:location event * add: support api:error event * add: support api:error event * ref: api:error: change log contents * ref: move api:* event handlers to a seperate file Co-authored-by: Artem Stoianov <zarianec91@gmail.com>
- Loading branch information
1 parent
b383161
commit b766a85
Showing
4 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {scopedLogger} from '../lib/logger.js'; | ||
import type {ProbeLocation} from '../types.js'; | ||
|
||
const logger = scopedLogger('api:connect'); | ||
|
||
export const apiConnectLocationHandler = (data: ProbeLocation): void => { | ||
logger.info(`connected from (${data.city}, ${data.country}, ${data.continent}) (lat: ${data.latitude} long: ${data.longitude})`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {scopedLogger} from '../lib/logger.js'; | ||
import type {WsApiError} from '../types.js'; | ||
|
||
const logger = scopedLogger('api:error'); | ||
|
||
export const apiErrorHandler = (error: WsApiError): void => { | ||
logger.error(`disconnected due to error (${error.info.socketId}):`, error); | ||
|
||
if (error.info.code === 'ip_limit') { | ||
logger.info('Only 1 connection per IP address is allowed. Please make sure you don\'t have another instance of the probe running.'); | ||
} | ||
|
||
if (error.info.probe) { | ||
const location = error.info.probe?.location; | ||
logger.debug(`attempted to connect from (${location.city}, ${location.country}, ${location.continent}) (lat: ${location.latitude} long: ${location.longitude})`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters