Repository: oppia/oppia

Issue:
Remove jinja from error pages
<!--
  - Thanks for taking the time to propose a new feature for the Oppia project.
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->
Find a solution for serving the error pages that will involve getting rid of the `status_code` GLOBAL
Possible solutions might include creating multiple error pages via webpack using the current error page a template and probably passing the status code in a similar manner as the title and metas are passed.


Remove jinja from error pages
<!--
  - Thanks for taking the time to propose a new feature for the Oppia project.
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->
Find a solution for serving the error pages that will involve getting rid of the `status_code` GLOBAL
Possible solutions might include creating multiple error pages via webpack using the current error page a template and probably passing the status code in a similar manner as the title and metas are passed.




Discussion:

Resolving patch:
diff --git a/core/controllers/base.py b/core/controllers/base.py
--- a/core/controllers/base.py
+++ b/core/controllers/base.py
@@ -367,7 +367,8 @@ def _render_exception_json_or_html(self, return_type, values):
                     'error-iframed.mainpage.html',
                     iframe_restriction=None)
             else:
-                self.render_template('error-page.mainpage.html')
+                self.render_template(
+                    'error-page-%s.mainpage.html' % values['status_code'])
         else:
             if return_type != feconf.HANDLER_TYPE_JSON and (
                     return_type != feconf.HANDLER_TYPE_DOWNLOADABLE):
@@ -383,6 +384,8 @@ def _render_exception(self, error_code, values):
                 400, 401, 404 or 500).
             values: dict. The key-value pairs to include in the response.
         """
+        # The error codes here should be in sync with the error pages
+        # generated via webpack.common.config.ts.
         assert error_code in [400, 401, 404, 500]
         values['status_code'] = error_code
         method = self.request.environ['REQUEST_METHOD']


Test patch:
diff --git a/core/tests/karma-globals.ts b/core/tests/karma-globals.ts
--- a/core/tests/karma-globals.ts
+++ b/core/tests/karma-globals.ts
@@ -17,8 +17,7 @@
  */
 
 var GLOBALS = {
-  status_code: '',
-  TRANSLATOR_PROVIDER_FOR_TESTS: null,
+  TRANSLATOR_PROVIDER_FOR_TESTS: null
 };
 
 /* This function overwrites the translationProvider for a dummy function
diff --git a/core/tests/protractor_desktop/navigation.js b/core/tests/protractor_desktop/navigation.js
--- a/core/tests/protractor_desktop/navigation.js
+++ b/core/tests/protractor_desktop/navigation.js
@@ -213,4 +213,11 @@ describe('Static Pages Tour', function() {
     expect(element(
       by.css('.protractor-test-thanks-page')).isPresent()).toBe(true);
   });
+
+  it('shows the error page when an incorrect url is given', function() {
+    browser.get('/splashes');
+    waitFor.pageToFullyLoad();
+    expect(element(
+      by.css('.protractor-test-error-page')).isPresent()).toBe(true);
+  });
 });