1
0
mirror of https://github.com/MailHops/mailhops-plugin.git synced 2025-05-19 23:50:13 -07:00

Added missed try catch around JSON.parse

Bump v1.0.6
This commit is contained in:
Andrew Van Tassel 2015-11-12 10:45:35 -07:00
parent dfa4f93bc0
commit a609e642d8
2 changed files with 22 additions and 23 deletions

View File

@ -8,7 +8,7 @@ var mailHops =
{ {
msgURI: null msgURI: null
, isLoaded: false , isLoaded: false
, options: {'version':'MailHops Plugin 1.0.5','lan':'en','unit':'mi','api_url':'http://api.mailhops.com','debug':false} , options: {'version':'MailHops Plugin 1.0.6','lan':'en','unit':'mi','api_url':'http://api.mailhops.com','debug':false}
, message: { secure:[] } , message: { secure:[] }
, client_location: null , client_location: null
}; };
@ -86,8 +86,7 @@ mailHops.StreamListener =
found: false , found: false ,
onDataAvailable: function ( request , context , inputStream , offset , count ) onDataAvailable: function ( request , context , inputStream , offset , count )
{ {
try try {
{
var sis = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance ( Components.interfaces.nsIScriptableInputStream ) ; var sis = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance ( Components.interfaces.nsIScriptableInputStream ) ;
sis.init( inputStream ) ; sis.init( inputStream ) ;
@ -104,8 +103,10 @@ mailHops.StreamListener =
this.found = true ; this.found = true ;
} }
} }
} catch(e) {
//failed to read input stream
mailHops.LOG('StreamListener Error: '+JSON.stringify(e));
} }
catch ( ex ) { }
} , } ,
onStartRequest: function ( request , context ) onStartRequest: function ( request , context )
{ {
@ -223,8 +224,7 @@ mailHops.getRoute = function(){
mailHops.testIP = function(ip,header){ mailHops.testIP = function(ip,header){
var retval = true; var retval = true;
try try {
{
var firstchar = header.substring(header.indexOf(ip)-1); var firstchar = header.substring(header.indexOf(ip)-1);
firstchar = firstchar.substring(0,1); firstchar = firstchar.substring(0,1);
var lastchar = header.substring((header.indexOf(ip)+ip.length)); var lastchar = header.substring((header.indexOf(ip)+ip.length));
@ -257,9 +257,9 @@ mailHops.testIP = function(ip,header){
else if(header.indexOf('version=TLSv1/SSLv3') != -1) else if(header.indexOf('version=TLSv1/SSLv3') != -1)
mailHops.message.secure.push(ip+':'+'using TLSv1/SSLv3'); mailHops.message.secure.push(ip+':'+'using TLSv1/SSLv3');
} }
} } catch(e) {
catch(ex) {
retval = true; retval = true;
mailHops.LOG('testIP Error: '+JSON.stringify(e));
} }
return retval; return retval;
}; };
@ -306,16 +306,11 @@ mailHops.getCharPref = function ( strName , strDefault ){
if (!pref){ if (!pref){
var pref = Components.classes["@mozilla.org/preferences-service;1"].getService( Components.interfaces.nsIPrefBranch ) ; var pref = Components.classes["@mozilla.org/preferences-service;1"].getService( Components.interfaces.nsIPrefBranch ) ;
} }
try {
try
{
value = pref.getCharPref ( strName ) ; value = pref.getCharPref ( strName ) ;
} } catch(e){
catch ( exception )
{
value = strDefault ; value = strDefault ;
} }
return ( value ) ; return ( value ) ;
}; };
@ -333,7 +328,7 @@ mailHops.setClientLocation = function(cb,api_url){
xmlhttp.onreadystatechange=function() { xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) { if (xmlhttp.readyState==4) {
try{ try {
var data = JSON.parse(xmlhttp.responseText); var data = JSON.parse(xmlhttp.responseText);
if(data && data.meta.code==200){ if(data && data.meta.code==200){
//display the result //display the result
@ -343,7 +338,7 @@ mailHops.setClientLocation = function(cb,api_url){
pref.setCharPref("mail.mailHops.client_location", '') ; pref.setCharPref("mail.mailHops.client_location", '') ;
cb(''); cb('');
} }
} catch (e){ } catch(e){
pref.setCharPref("mail.mailHops.client_location", '') ; pref.setCharPref("mail.mailHops.client_location", '') ;
cb(''); cb('');
} }
@ -373,9 +368,13 @@ mailHops.lookupRoute = function(header_route){
if(cached_results){ if(cached_results){
mailHops.LOG('Found Cached Result'); mailHops.LOG('Found Cached Result');
cached_results = JSON.parse(cached_results); try {
mailHopsDisplay.route(header_route, mailHops.message, cached_results.response, cached_results.meta, lookupURL); cached_results = JSON.parse(cached_results);
return; mailHopsDisplay.route(header_route, mailHops.message, cached_results.response, cached_results.meta, lookupURL);
return;
} catch(e){
mailHops.LOG('Failed to parse cached result: '+JSON.stringify(e));
}
} }
//call mailhops api for lookup //call mailhops api for lookup
@ -400,8 +399,8 @@ mailHops.lookupRoute = function(header_route){
//display the error //display the error
mailHopsDisplay.error(data); mailHopsDisplay.error(data);
} }
} catch (ex){ } catch(e){
mailHops.LOG(JSON.stringify(ex)); mailHops.LOG(JSON.stringify(e));
mailHopsDisplay.error(); mailHopsDisplay.error();
} }
} }

View File

@ -5,7 +5,7 @@
<Description about="urn:mozilla:install-manifest"> <Description about="urn:mozilla:install-manifest">
<em:type>2</em:type> <em:type>2</em:type>
<em:id>thunderbird@mailhops.com</em:id> <em:id>thunderbird@mailhops.com</em:id>
<em:version>1.0.5</em:version> <em:version>1.0.6</em:version>
<em:name>MailHops</em:name> <em:name>MailHops</em:name>
<em:description>MailHops maps the route an email traveled to get to you. Using GeoIP it also displays distance traveled along with the location (city, state and country) of the sender.</em:description> <em:description>MailHops maps the route an email traveled to get to you. Using GeoIP it also displays distance traveled along with the location (city, state and country) of the sender.</em:description>