Browse Source

HUE-4827 [fb] Pointing to a wrong S3 region breaks with no information

Jenny Kim 9 years ago
parent
commit
6c4c214
2 changed files with 15 additions and 3 deletions
  1. 9 0
      apps/filebrowser/src/filebrowser/views.py
  2. 6 3
      desktop/libs/aws/src/aws/s3/s3fs.py

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

@@ -191,6 +191,15 @@ def view(request, path):
           return JsonResponse(exception)
           return JsonResponse(exception)
         else:
         else:
           raise PopupException(msg , detail=e)
           raise PopupException(msg , detail=e)
+    except S3FileSystemException, e:
+        msg = _("S3 filesystem exception.")
+        if request.is_ajax():
+            exception = {
+                'error': smart_str(e)
+            }
+            return JsonResponse(exception)
+        else:
+            raise PopupException(msg, detail=e)
 
 
 
 
 def home_relative_view(request, path):
 def home_relative_view(request, path):

+ 6 - 3
desktop/libs/aws/src/aws/s3/s3fs.py

@@ -106,9 +106,12 @@ class S3FileSystem(object):
     bucket = self._get_bucket(bucket_name)
     bucket = self._get_bucket(bucket_name)
     try:
     try:
       return bucket.get_key(key_name, validate=validate)
       return bucket.get_key(key_name, validate=validate)
-    except:
-      e, exc, tb = sys.exc_info()
-      raise ValueError(e)
+    except S3ResponseError, e:
+      if e.status == 301:
+        raise S3FileSystemException(_('Failed to access path: "%s". '
+          'Check that you have access to read this bucket and that the region is correct.') % path)
+      else:
+        raise S3FileSystemException(e.reason)
 
 
   def _get_location(self):
   def _get_location(self):
     if get_default_region() in (Location.EU, Location.EUCentral1, Location.USWest, Location.USWest2, Location.SAEast,
     if get_default_region() in (Location.EU, Location.EUCentral1, Location.USWest, Location.USWest2, Location.SAEast,