1- /* eslint-disable max-lines-per-function */
1+ /* eslint-disable max-lines-per-function, no-console */
22import { hostname , platform , release } from "os" ;
33import { convertRequestBodyToString } from "../helpers/convertRequestBodyToString" ;
44import { getAgentVersion } from "../helpers/getAgentVersion" ;
@@ -113,6 +113,18 @@ export class Agent {
113113 this . timeoutInMS
114114 ) ;
115115
116+ if ( ! result . success ) {
117+ if ( result . error === "invalid_token" ) {
118+ console . error (
119+ "Aikido: Unable to access the Aikido platform, please check your token."
120+ ) ;
121+ } else {
122+ console . error (
123+ `Aikido: Failed to connect to the Aikido platform: ${ result . error } `
124+ ) ;
125+ }
126+ }
127+
116128 this . updateServiceConfig ( result ) ;
117129
118130 await this . updateBlockedLists ( ) ;
@@ -193,8 +205,10 @@ export class Agent {
193205 this . attackLogger . log ( attack ) ;
194206
195207 if ( this . token ) {
196- this . api . report ( this . token , attack , this . timeoutInMS ) . catch ( ( ) => {
197- this . logger . log ( "Failed to report attack" ) ;
208+ this . api . report ( this . token , attack , this . timeoutInMS ) . catch ( ( err ) => {
209+ console . error (
210+ `Aikido: Failed to report attack event to Aikido platform: ${ err . message } `
211+ ) ;
198212 } ) ;
199213 }
200214 }
@@ -203,8 +217,10 @@ export class Agent {
203217 * Sends a heartbeat via the API to the server (only when not in serverless mode)
204218 */
205219 private heartbeat ( timeoutInMS = this . timeoutInMS ) {
206- this . sendHeartbeat ( timeoutInMS ) . catch ( ( ) => {
207- this . logger . log ( "Failed to do heartbeat" ) ;
220+ this . sendHeartbeat ( timeoutInMS ) . catch ( ( err ) => {
221+ console . error (
222+ `Aikido: Failed to send heartbeat event to Aikido platform: ${ err . message } `
223+ ) ;
208224 } ) ;
209225 }
210226
@@ -291,6 +307,12 @@ export class Agent {
291307 timeoutInMS
292308 ) ;
293309
310+ if ( ! response . success && response . error === "invalid_token" ) {
311+ console . error (
312+ "Aikido: Unable to access the Aikido platform, please check your token."
313+ ) ;
314+ }
315+
294316 this . updateServiceConfig ( response ) ;
295317 }
296318 }
@@ -354,7 +376,7 @@ export class Agent {
354376 this . serviceConfig . updateBlockedIPAddresses ( blockedIPAddresses ) ;
355377 this . serviceConfig . updateBlockedUserAgents ( blockedUserAgents ) ;
356378 } catch ( error : any ) {
357- this . logger . log ( ` Failed to update blocked lists: ${ error . message } `) ;
379+ console . error ( `Aikido: Failed to update blocked lists: ${ error . message } `) ;
358380 }
359381 }
360382
@@ -432,7 +454,6 @@ export class Agent {
432454 this . logger . log ( "No token provided, disabling reporting." ) ;
433455
434456 if ( ! this . block && ! isAikidoCI ( ) ) {
435- // eslint-disable-next-line no-console
436457 console . log (
437458 "AIKIDO: Running in monitoring only mode without reporting to Aikido Cloud. Set AIKIDO_BLOCK=true to enable blocking."
438459 ) ;
0 commit comments