From 590a4634d873b3fd3532d0f32edea64838d80b8d Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Mon, 26 Sep 2022 13:52:07 -0600 Subject: [PATCH] Log unknown SendGrid HTTP errors --- models/protocols/SendGridProtocol.cfc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/protocols/SendGridProtocol.cfc b/models/protocols/SendGridProtocol.cfc index bf5870d..6215411 100644 --- a/models/protocols/SendGridProtocol.cfc +++ b/models/protocols/SendGridProtocol.cfc @@ -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']; }