ソースを参照

HUE-3670 [jb] Summary button does not fail gracefully

Romain Rigaux 9 年 前
コミット
09c7074

+ 10 - 2
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -950,8 +950,16 @@ from django.utils.translation import ugettext as _
         self.isLoadingSummary(true);
         $("#contentSummaryModal").modal("show");
         $.getJSON("${url('filebrowser.views.content_summary', path='')}" + self.selectedFile().path, function (data) {
-          self.contentSummary(ko.mapping.fromJS(data));
-          self.isLoadingSummary(false);
+          if (data.status == 0) {
+            self.contentSummary(ko.mapping.fromJS(data.summary));
+            self.isLoadingSummary(false);
+          } else {
+            $(document).trigger("error", data.message);
+            $("#contentSummaryModal").modal("hide");
+          }
+        }).fail(function (xhr, textStatus, errorThrown) {
+          $(document).trigger("error", xhr.responseText);
+          $("#contentSummaryModal").modal("hide");
         });
       }
 

+ 9 - 2
apps/filebrowser/src/filebrowser/views.py

@@ -517,8 +517,15 @@ def stat(request, path):
 def content_summary(request, path):
     if not request.fs.exists(path):
         raise Http404(_("File not found: %(path)s") % {'path': escape(path)})
-    stats = request.fs.get_content_summary(path)
-    return JsonResponse(stats.summary)
+
+    response = {'status': -1, 'message': '', 'summary': None}
+    try:
+        stats = request.fs.get_content_summary(path)
+        response['status'] = 0
+        response['summary'] = stats.summary
+    except WebHdfsException, e:
+        response['message'] = _("The file could not be saved") + e.message.splitlines()[0]
+    return JsonResponse(response)
 
 
 def display(request, path):