@@ -13,27 +13,41 @@ component {
13
13
*/
14
14
property name = " interceptorService" inject = " coldbox:interceptorService" ;
15
15
16
+ /**
17
+ * SendGrid Module Settings
18
+ */
19
+ property name = " log" inject = " logbox:logger:{this}" ;
20
+
16
21
/**
17
22
* Translate incoming webhooks to ColdBox interceptors
18
23
*/
19
24
function handle ( event , rc , prc ) {
20
25
if ( needsAuth () ) {
26
+ log .debug ( " Authentication is set up for SendGrid SDK. Checking credentials now" );
21
27
if ( isPartialAuthCredentials () ) {
28
+ log .warn ( " Partial authentication detected for SendGrid SDK." , sendgridSettings );
22
29
return event .renderData ( statusCode = 500 , data = " Invalid auth configuration" );
23
30
}
24
31
if ( isInvalidAuthCredentials ( event ) ) {
32
+ log .info ( " Invalid incoming credentials detected for SendGrid webhook endpoint" , {
33
+ " incomingCredentials" : event .getHTTPBasicCredentials (),
34
+ " sendgridSettings" : sendgridSettings
35
+ } );
25
36
return event .renderData ( statusCode = 401 , data = " Invalid credentials" );
26
37
}
27
38
}
28
39
29
40
var webhookEvents = event .getHTTPContent ( json = true );
41
+ log .debug ( " Converting incoming webhook events to interception points" , webhookEvents );
30
42
for ( var webhookEvent in webhookEvents ) {
43
+ log .debug ( " Announcing #generateStateName ( webhookEvent ) # SendGrid event" , webhookEvent );
31
44
interceptorService .processState (
32
45
generateStateName ( webhookEvent ),
33
46
webhookEvent
34
47
);
35
48
}
36
49
50
+ log .debug ( " All events announced. Returning 200 to SendGrid" );
37
51
return event .renderData ( statusCode = 200 , data = " Successfully caught the webhook" );
38
52
}
39
53
0 commit comments