Skip to content

Commit 63f355f

Browse files
committed
fix(Webhooks): Add logging for easier debugging
1 parent 06e3bcb commit 63f355f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

modules/sendgrid-sdk/handlers/webhooks.cfc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,41 @@ component {
1313
*/
1414
property name="interceptorService" inject="coldbox:interceptorService";
1515

16+
/**
17+
* SendGrid Module Settings
18+
*/
19+
property name="log" inject="logbox:logger:{this}";
20+
1621
/**
1722
* Translate incoming webhooks to ColdBox interceptors
1823
*/
1924
function handle( event, rc, prc ) {
2025
if ( needsAuth() ) {
26+
log.debug( "Authentication is set up for SendGrid SDK. Checking credentials now" );
2127
if ( isPartialAuthCredentials() ) {
28+
log.warn( "Partial authentication detected for SendGrid SDK.", sendgridSettings );
2229
return event.renderData( statusCode = 500, data = "Invalid auth configuration" );
2330
}
2431
if ( isInvalidAuthCredentials( event ) ) {
32+
log.info( "Invalid incoming credentials detected for SendGrid webhook endpoint", {
33+
"incomingCredentials": event.getHTTPBasicCredentials(),
34+
"sendgridSettings": sendgridSettings
35+
} );
2536
return event.renderData( statusCode = 401, data = "Invalid credentials" );
2637
}
2738
}
2839

2940
var webhookEvents = event.getHTTPContent( json = true );
41+
log.debug( "Converting incoming webhook events to interception points", webhookEvents );
3042
for ( var webhookEvent in webhookEvents ) {
43+
log.debug( "Announcing #generateStateName( webhookEvent )# SendGrid event", webhookEvent );
3144
interceptorService.processState(
3245
generateStateName( webhookEvent ),
3346
webhookEvent
3447
);
3548
}
3649

50+
log.debug( "All events announced. Returning 200 to SendGrid" );
3751
return event.renderData( statusCode = 200, data = "Successfully caught the webhook" );
3852
}
3953

0 commit comments

Comments
 (0)