diff --git a/frontend/template-partials/translations/src/en/errors.json b/frontend/template-partials/translations/src/en/errors.json
index 9909048a..9bbcfe22 100644
--- a/frontend/template-partials/translations/src/en/errors.json
+++ b/frontend/template-partials/translations/src/en/errors.json
@@ -11,6 +11,11 @@
"title": "Page not found",
"description": "This page does not exist"
},
+ "403": {
+ "title": "Page is Forbidden",
+ "description": "This page is Forbidden",
+ "paragraph": "This page is Forbidden"
+ },
"cookies-required": {
"title": "Cookies are required to use this service",
"message": "Cookies are required in order to use this service.
Please enable cookies and try again. Find out how to we use cookies."
diff --git a/frontend/template-partials/views/403.html b/frontend/template-partials/views/403.html
new file mode 100644
index 00000000..d567f312
--- /dev/null
+++ b/frontend/template-partials/views/403.html
@@ -0,0 +1,18 @@
+{{
+
+
+
+
{{title}}
+
{{paragraph}}
+
+
+
+
+ {{#t}}buttons.start-again{{/t}}
+ {{/content}}
+{{/layout}}
diff --git a/middleware/errors.js b/middleware/errors.js
index 63ccc274..1c86f32b 100644
--- a/middleware/errors.js
+++ b/middleware/errors.js
@@ -17,14 +17,20 @@ const getContent = (err, translate) => {
content.title = (translate && translate('errors.session.title'));
content.message = (translate && translate('errors.session.message'));
}
-
if (err.code === 'NO_COOKIES') {
- err.status = 403;
+ err.status = 432;
err.template = 'cookie-error';
content.title = (translate && translate('errors.cookies-required.title'));
content.message = (translate && translate('errors.cookies-required.message'));
}
-
+ if (err.code === 'FORBIDDEN') {
+ err.status = 403;
+ err.template = '403';
+ err.title = (translate && translate('errors.403.title'));
+ err.message = (translate && translate('errors.403.description'));
+ content.title = (translate && translate('errors.403.title'));
+ content.message = (translate && translate('errors.403.description'));
+ }
if (err.code === 'DDOS_RATE_LIMIT') {
err.status = 429;
err.template = 'rate-limit-error';
diff --git a/test/middleware/errors.spec.js b/test/middleware/errors.spec.js
index 4e0d68ec..bbc1075a 100644
--- a/test/middleware/errors.spec.js
+++ b/test/middleware/errors.spec.js
@@ -98,7 +98,7 @@ describe('errors', () => {
res.render.should.have.been.calledWith('error', sinon.match(locals));
});
- it('renders the `error` template with `403` status', () => {
+ it('renders the `error` template with `432` status', () => {
const err = {
code: 'NO_COOKIES'
};
@@ -112,11 +112,30 @@ describe('errors', () => {
middleware(err, req, res, next);
- res.status.should.have.been.calledWith(403);
+ res.status.should.have.been.calledWith(432);
res.render.should.have.been.calledWith('cookie-error', sinon.match(locals));
res.render.should.have.been.calledWith('error', sinon.match(locals));
});
+ it('renders the `error` template with `403` status', () => {
+ const err = {
+ code: 'FORBIDDEN'
+ };
+
+ const locals = {
+ content: {message: 'errors.403.description', title: 'errors.403.title'},
+ error: err,
+ showStack: false,
+ startLink: '/'
+ };
+
+ middleware(err, req, res, next);
+
+ res.status.should.have.been.calledWith(403);
+ res.render.should.have.been.calledWith('403', sinon.match(locals));
+ res.render.should.have.been.calledWith('error', sinon.match(locals));
+ });
+
it('renders the `error` template with `500` status', () => {
const err = {
code: 'UNKNOWN'
@@ -158,7 +177,7 @@ describe('errors', () => {
res.send.should.have.been.calledWith(html);
});
- it('renders the `cookie-error` template with `403` status for cookie errors', () => {
+ it('renders the `cookie-error` template with `432` status for cookie errors', () => {
res.render.withArgs('cookie-error').yields(null, html);
const err = {
@@ -174,10 +193,28 @@ describe('errors', () => {
middleware(err, req, res, next);
- res.status.should.have.been.calledWith(403);
+ res.status.should.have.been.calledWith(432);
res.render.should.have.been.calledWith('cookie-error', sinon.match(locals));
res.send.should.have.been.calledWith(html);
});
+ it('renders the `403` template with `403` status for forbidden', () => {
+ res.render.withArgs('403').yields(null, html);
+
+ const err = {
+ code: 'FORBIDDEN'
+ };
+
+ const locals = {
+ content: {message: 'errors.403.description', title: 'errors.403.title'},
+ error: err,
+ showStack: false,
+ startLink: '/'
+ };
+ middleware(err, req, res, next);
+ res.status.should.have.been.calledWith(403);
+ res.render.should.have.been.calledWith('403', sinon.match(locals));
+ res.send.should.have.been.calledWith(html);
+ });
it('renders the `error` template with `500` status for unknown errors', () => {
res.render.withArgs('error').yields(null, html);