Skip to content

Commit

Permalink
Log unknown SendGrid HTTP errors
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Sep 26, 2022
1 parent 4d3684c commit 590a463
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion models/protocols/SendGridProtocol.cfc
Expand Up @@ -120,12 +120,17 @@ component extends="cbmailservices.models.AbstractProtocol" {
cfhttpparam( type = "body", value = serializeJson( body ) );
};

if ( left( cfhttp.status_code, 1 ) != "2" && left( cfhttp.status_code, 1 ) != "3" ) {
if ( !structKeyExists( cfhttp, "responseheader" ) || !structKeyExists( cfhttp.responseheader, "status_code" ) ) {
log.error( "An unknown error occured when sending the http request to SendGrid", cfhttp );
rtnStruct.messages = [ "An unknown error occurred" ];
}
else if ( left( cfhttp.responseheader.status_code, 1 ) != "2" && left( cfhttp.responseheader.status_code, 1 ) != "3" ) {
rtnStruct.messages = deserializeJSON( cfhttp.filecontent ).errors;
}
else {
rtnStruct.error = false;
}

if ( StructKeyExists(cfhttp,'responseheader') AND StructKeyExists(cfhttp.responseheader,'X-Message-Id') ) {
rtnStruct.messageID = cfhttp.responseheader['X-Message-Id'];
}
Expand Down

0 comments on commit 590a463

Please sign in to comment.