From 4d2025c5f41a9f7537094fa62d5315e83a289cb6 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 19 Dec 2016 13:39:40 +0000 Subject: [PATCH] enhanced exception handling in some view files --- codepot/src/codepot/views/code_file.php | 7 +++++-- codepot/src/codepot/views/code_folder.php | 17 +++++++++++++---- codepot/src/codepot/views/graph_main.php | 13 ++++++++----- codepot/src/codepot/views/project_map.php | 4 +++- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/codepot/src/codepot/views/code_file.php b/codepot/src/codepot/views/code_file.php index d443e49e..6178d4f3 100644 --- a/codepot/src/codepot/views/code_file.php +++ b/codepot/src/codepot/views/code_file.php @@ -237,7 +237,10 @@ var revision_network = null; function show_revision_graph (response) { - var data = $.parseJSON(response); + var data; + try { data = $.parseJSON(response); } + catch (e) { data = null; } + if (data == null) { show_alert ('Invalid data received', "lang->line('Error')?>"); @@ -252,7 +255,7 @@ function show_revision_graph (response) autoResize: false, height: '500px', width: '100%', - clickToUse: true, + clickToUse: false, layout: { hierarchical: { enabled: true, diff --git a/codepot/src/codepot/views/code_folder.php b/codepot/src/codepot/views/code_folder.php index 9700076b..753665a3 100644 --- a/codepot/src/codepot/views/code_folder.php +++ b/codepot/src/codepot/views/code_folder.php @@ -107,7 +107,10 @@ function show_tooltip(id, x, y, contents) { function show_loc_by_lang_graph (response) { - var loc = $.parseJSON(response); + var loc; + try { loc = $.parseJSON(response); } + catch (e) { loc = null; } + if (loc == null) { show_alert ('Invalid data received', "lang->line('Error')?>"); @@ -186,7 +189,10 @@ function show_loc_by_lang_graph (response) function show_loc_by_file_graph (response) { - var loc = $.parseJSON(response); + var loc; + try { loc = $.parseJSON(response); } + catch (e) { loc = null; } + if (loc == null) { show_alert ('Invalid data received', "lang->line('Error')?>"); @@ -205,7 +211,10 @@ var revision_network = null; function show_revision_graph (response) { - var data = $.parseJSON(response); + var data; + try { data = $.parseJSON(response); } + catch (e) { data = null; } + if (data == null) { show_alert ('Invalid data received', "lang->line('Error')?>"); @@ -220,7 +229,7 @@ function show_revision_graph (response) autoResize: false, height: '500px', width: '100%', - clickToUse: true, + clickToUse: false, layout: { hierarchical: { enabled: true, diff --git a/codepot/src/codepot/views/graph_main.php b/codepot/src/codepot/views/graph_main.php index d4c1a9da..1c64362d 100644 --- a/codepot/src/codepot/views/graph_main.php +++ b/codepot/src/codepot/views/graph_main.php @@ -395,15 +395,18 @@ function show_commits_per_user_graph(log) function show_all_graphs (response) { - var log = $.parseJSON(response); - if (log == null) + var data; + try { data = $.parseJSON(response); } + catch (e) { data = null; } + + if (data == null) { alert ('Invalid data received'); } - else if (log.length > 0) + else if (data.length > 0) { - show_commits_per_month_graph (log); - show_commits_per_user_graph (log); + show_commits_per_month_graph (data); + show_commits_per_user_graph (data); } else { diff --git a/codepot/src/codepot/views/project_map.php b/codepot/src/codepot/views/project_map.php index f66db6cb..aca71274 100644 --- a/codepot/src/codepot/views/project_map.php +++ b/codepot/src/codepot/views/project_map.php @@ -144,7 +144,9 @@ var GraphApp = (function() function show_graph (response) { - var data = $.parseJSON(response); + var data; + try { data = $.parseJSON(response); } // TODO: for jquery 3.0 or later, JSON.parse() should be used. + catch (e) { data = null; } if (data == null) {