1
- /* eslint-disable max-lines-per-function */
1
+ /* eslint-disable max-lines-per-function, no-console */
2
2
import { hostname , platform , release } from "os" ;
3
3
import { convertRequestBodyToString } from "../helpers/convertRequestBodyToString" ;
4
4
import { getAgentVersion } from "../helpers/getAgentVersion" ;
@@ -113,12 +113,27 @@ export class Agent {
113
113
this . timeoutInMS
114
114
) ;
115
115
116
+ this . checkForReportingAPIError ( result ) ;
116
117
this . updateServiceConfig ( result ) ;
117
118
118
119
await this . updateBlockedLists ( ) ;
119
120
}
120
121
}
121
122
123
+ checkForReportingAPIError ( result : ReportingAPIResponse ) {
124
+ if ( ! result . success ) {
125
+ if ( result . error === "invalid_token" ) {
126
+ console . error (
127
+ "Aikido: We were unable to connect to the Aikido platform. Please verify that your token is correct."
128
+ ) ;
129
+ } else {
130
+ console . error (
131
+ `Aikido: Failed to connect to the Aikido platform: ${ result . error } `
132
+ ) ;
133
+ }
134
+ }
135
+ }
136
+
122
137
onErrorThrownByInterceptor ( {
123
138
error,
124
139
module,
@@ -193,7 +208,7 @@ export class Agent {
193
208
this . attackLogger . log ( attack ) ;
194
209
195
210
if ( this . token ) {
196
- this . api . report ( this . token , attack , this . timeoutInMS ) . catch ( ( ) => {
211
+ this . api . report ( this . token , attack , this . timeoutInMS ) . catch ( ( err ) => {
197
212
this . logger . log ( "Failed to report attack" ) ;
198
213
} ) ;
199
214
}
@@ -203,7 +218,7 @@ export class Agent {
203
218
* Sends a heartbeat via the API to the server (only when not in serverless mode)
204
219
*/
205
220
private heartbeat ( timeoutInMS = this . timeoutInMS ) {
206
- this . sendHeartbeat ( timeoutInMS ) . catch ( ( ) => {
221
+ this . sendHeartbeat ( timeoutInMS ) . catch ( ( err ) => {
207
222
this . logger . log ( "Failed to do heartbeat" ) ;
208
223
} ) ;
209
224
}
@@ -354,7 +369,7 @@ export class Agent {
354
369
this . serviceConfig . updateBlockedIPAddresses ( blockedIPAddresses ) ;
355
370
this . serviceConfig . updateBlockedUserAgents ( blockedUserAgents ) ;
356
371
} catch ( error : any ) {
357
- this . logger . log ( ` Failed to update blocked lists: ${ error . message } `) ;
372
+ console . error ( `Aikido: Failed to update blocked lists: ${ error . message } `) ;
358
373
}
359
374
}
360
375
@@ -432,7 +447,6 @@ export class Agent {
432
447
this . logger . log ( "No token provided, disabling reporting." ) ;
433
448
434
449
if ( ! this . block && ! isAikidoCI ( ) ) {
435
- // eslint-disable-next-line no-console
436
450
console . log (
437
451
"AIKIDO: Running in monitoring only mode without reporting to Aikido Cloud. Set AIKIDO_BLOCK=true to enable blocking."
438
452
) ;
@@ -448,8 +462,8 @@ export class Agent {
448
462
this . startHeartbeats ( ) ;
449
463
this . startPollingForConfigChanges ( ) ;
450
464
} )
451
- . catch ( ( ) => {
452
- this . logger . log ( " Failed to start agent" ) ;
465
+ . catch ( ( err ) => {
466
+ console . error ( `Aikido: Failed to start agent: ${ err . message } ` ) ;
453
467
} ) ;
454
468
}
455
469
0 commit comments