Repository: CSCfi/swift-browser-ui

Issue:
Failure to retrieve containers after switching to a a project with no containers
#### Describe the bug
Failure to retrieve containers after switching to a a project with no containers

#### To Reproduce
Steps to reproduce the behaviour:
1. Log in
2.1 If there is a project with some containers available switch to one without anything
2.2 If there is a project with no containers available switch to one with some containers
4. See error

#### Expected behavior
Display the available containers if they are present.

#### Screenshots
![Peek 2019-08-19 15-18](https://user-images.githubusercontent.com/47524/63264800-a45cbc00-c294-11e9-8368-698b6b43b2ba.gif)

#### Additional context
<!-- Add any other context about the problem here. -->


Discussion:

Patch:
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 861c746a..c2766881 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -28,7 +28,7 @@ copyright = f'{current_year}, CSC Developers'
 author = 'CSC Developers'
 
 # The full version, including alpha/beta/rc tags
-version = release = '0.3.2'
+version = release = '0.3.3'
 
 
 # -- General configuration ---------------------------------------------------
diff --git a/swift_browser_ui/__init__.py b/swift_browser_ui/__init__.py
index a1d3d29a..330337d2 100644
--- a/swift_browser_ui/__init__.py
+++ b/swift_browser_ui/__init__.py
@@ -7,6 +7,6 @@ with the object storage.
 
 
 __name__ = 'swift_browser_ui'
-__version__ = '0.3.2'
+__version__ = '0.3.3'
 __author__ = 'CSC Developers'
 __license__ = 'MIT License'
diff --git a/swift_browser_ui/middlewares.py b/swift_browser_ui/middlewares.py
index 3a857ab8..3f08bf77 100644
--- a/swift_browser_ui/middlewares.py
+++ b/swift_browser_ui/middlewares.py
@@ -5,41 +5,40 @@ from aiohttp import web
 from .settings import setd
 
 
+def return_error_response(error_code):
+    """Return the correct error page with correct status code."""
+    with open(
+            setd["static_directory"] + "/" + str(error_code) + ".html"
+    ) as resp:
+        return web.Response(
+            body="".join(resp.readlines()),
+            status=error_code,
+            content_type="text/html",
+            headers={
+                "Cache-Control": "no-cache, no-store, must-revalidate",
+                "Pragma": "no-cache",
+                "Expires": "0"
+            }
+        )
+
+
 @web.middleware
 async def error_middleware(request, handler):
     """Return the correct HTTP Error page."""
     try:
         response = await handler(request)
         if response.status == 401:
-            return web.FileResponse(
-                setd["static_directory"] + "/401.html",
-                status=401
-            )
+            return return_error_response(401)
         if response.status == 403:
-            return web.FileResponse(
-                setd["static_directory"] + "/403.html",
-                status=403
-            )
+            return return_error_response(403)
         if response.status == 404:
-            return web.FileResponse(
-                setd["static_directory"] + "/404.html",
-                status=404
-            )
+            return return_error_response(404)
         return response
     except web.HTTPException as ex:
         if ex.status == 401:
-            return web.FileResponse(
-                setd["static_directory"] + "/401.html",
-                status=401
-            )
+            return return_error_response(401)
         if ex.status == 403:
-            return web.FileResponse(
-                setd["static_directory"] + "/403.html",
-                status=403
-            )
+            return return_error_response(403)
         if ex.status == 404:
-            return web.FileResponse(
-                setd["static_directory"] + "/404.html",
-                status=404
-            )
+            return return_error_response(404)
         raise
diff --git a/tox.ini b/tox.ini
index ab953fc3..d983294d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -16,7 +16,7 @@ deps =
     pydocstyle==3.0.0
     flake8
     flake8-docstrings
-commands = flake8 .
+commands = flake8 swift_browser_ui tests ui_tests
 
 [testenv:docs]
 ; skip_install = true


Test patch:
diff --git a/tests/test_middlewares.py b/tests/test_middlewares.py
index 84bad576..3c54417d 100644
--- a/tests/test_middlewares.py
+++ b/tests/test_middlewares.py
@@ -52,37 +52,37 @@ class MiddlewareTestClass(asynctest.TestCase):
         """Test 401 middleware when the 401 status is returned."""
         resp = await error_middleware(None, return_401_handler)
         self.assertEqual(resp.status, 401)
-        self.assertIsInstance(resp, FileResponse)
+        self.assertIsInstance(resp, Response)
 
     async def test_401_exception(self):
         """Test 401 middleware when the 401 status is risen."""
         resp = await error_middleware(True, return_401_handler)
         self.assertEqual(resp.status, 401)
-        self.assertIsInstance(resp, FileResponse)
+        self.assertIsInstance(resp, Response)
 
     async def test_403_return(self):
         """Test 403 middleware when the 403 status is returned."""
         resp = await error_middleware(None, return_403_handler)
         self.assertEqual(resp.status, 403)
-        self.assertIsInstance(resp, FileResponse)
+        self.assertIsInstance(resp, Response)
 
     async def test_403_exception(self):
         """Test 403 middleware when the 403 status is risen."""
         resp = await error_middleware(True, return_403_handler)
         self.assertEqual(resp.status, 403)
-        self.assertIsInstance(resp, FileResponse)
+        self.assertIsInstance(resp, Response)
 
     async def test_404_return(self):
         """Test 404 middleware when the 404 status is returned."""
         resp = await error_middleware(None, return_404_handler)
         self.assertEqual(resp.status, 404)
-        self.assertIsInstance(resp, FileResponse)
+        self.assertIsInstance(resp, Response)
 
     async def test_404_exception(self):
         """Test 404 middlewrae when the 404 status is risen."""
         resp = await error_middleware(True, return_404_handler)
         self.assertEqual(resp.status, 404)
-        self.assertIsInstance(resp, FileResponse)
+        self.assertIsInstance(resp, Response)
 
     async def test_error_middleware_no_error(self):
         """Test the general error middleware with correct status."""