Checking URLs with UrlFetchApp. Getting SSL Errors

766 views
Skip to first unread message

Aaron Weiner

unread,
Jun 1, 2016, 2:09:42 PM6/1/16
to AdWords Scripts Forum
Hello, 

I have a script that checks my client's final URLs and their status codes - (201,301,404 and so on). 

The problem that I have run into is when there is an SSL Error. 

I want to know about that but SSL Errors seem to cause errors in the code itself. 

Instead of continuing on with the running of the code, it breaks the code which in turn stops checking other URLs. 

The last thing I want to do is set "validateHttpsCertificates: false" because I would want to know if there is an SSL issue. 

This is the code that I am using:

function getUrlStatus(url) {
  var response = UrlFetchApp.fetch(url, { muteHttpExceptions: true, validateHttpsCertificates: true});
  if (response.getResponseCode()!== 200){
    Logger.log("URL Error: %s \n %s",response.getResponseCode(), response);  
  }  
  return response.getResponseCode();
}

How would I keep the code running instead of breaking on these types of SSL errors?

Thanks and I look forward to your reply.

Jaren Callo (AdWords Scripts Team)

unread,
Jun 1, 2016, 3:46:03 PM6/1/16
to AdWords Scripts Forum
Hi Aaron,

What I can suggest is to have try-catch handle such scenarios and proceed with the rest.

Thanks,
Jaren P. Callo
AdWords Scripts Team


Aaron Weiner

unread,
Jun 1, 2016, 4:03:16 PM6/1/16
to AdWords Scripts Forum
Do you mean something like this?

function getUrlStatus(url) {  
  try{
    var response = UrlFetchApp.fetch(url, { muteHttpExceptions: true, validateHttpsCertificates: true});
    
    if (response.getResponseCode()!== 200){
      Logger.log("URL Error: %s \n %s",response.getResponseCode(), response);
    }
    return response.getResponseCode();
  } catch(e){
    Logger.log("URL Error: %s \n %s",url, e);
    return e
  }
}

I tested it and it does seem to work but if you think it should be formatted differently, please do let me know. 

Thank you.

Jaren Callo (AdWords Scripts Team)

unread,
Jun 1, 2016, 4:07:36 PM6/1/16
to AdWords Scripts Forum
Hi Aaron,

Thats exactly how it should be.

Thanks,
Jaren P. Callo
AdWords Scripts Team

Aaron Weiner

unread,
Jun 1, 2016, 4:10:06 PM6/1/16
to AdWords Scripts Forum
Thank you. 

Aaron. 
Reply all
Reply to author
Forward
0 new messages