Skip to content

Commit 6f101fa

Browse files
committed
before cleanup
1 parent a8c756d commit 6f101fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+287
-647
lines changed

dev

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export ASSET_VERSIONING=query
1010
export WATCH=1
1111
export SITE_HOST=http://javascript.local
1212
export PORT=3000
13+
export TUTORIAL_EDIT=
1314

1415
npm --silent run gulp dev | bunyan -o short -l debug
1516

handlers/404.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports.init = function(app) {
66
await next();
77

88
if (ctx.status === 404) {
9-
// still nothing found? let default errorHandler show 404
9+
// still nothing found? let default error show 404
1010
ctx.throw(404);
1111
}
1212
});

handlers/dev/templates/index.pug

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
extends /layouts/main
33

44
block append variables
5-
- let sitetoolbar = true
65
- let title = "Test page"
76

87

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ const path = require('path');
55

66
let isDevelopment = process.env.NODE_ENV == 'development';
77

8+
9+
const t = require('i18n');
10+
t.requirePhrase('error');
11+
12+
813
// can be called not from this MW, but from anywhere
914
// this.templateDir can be anything
1015
function renderError(ctx, err) {
@@ -29,6 +34,11 @@ function renderError(ctx, err) {
2934

3035
let preferredType = ctx.accepts('html', 'json');
3136

37+
// malformed or absent mongoose params
38+
if (err.name == 'CastError' && process.env.NODE_ENV == 'production') {
39+
ctx.status = 400;
40+
}
41+
3242
if (err.name == 'ValidationError') {
3343
ctx.status = 400;
3444

@@ -44,7 +54,6 @@ function renderError(ctx, err) {
4454
};
4555
} else {
4656
ctx.body = ctx.render(path.join(__dirname, "templates/400"), {
47-
useAbsoluteTemplatePath: true,
4857
error: err
4958
});
5059
}
@@ -86,11 +95,13 @@ function renderError(ctx, err) {
8695
ctx.body.description = err.description;
8796
}
8897
} else {
89-
let templateName = ~[500, 401, 404, 403].indexOf(ctx.status) ? ctx.status : 500;
98+
let templateName = [503, 500, 401, 404, 403].includes(ctx.status) ? ctx.status : 500;
9099
ctx.body = ctx.render(`${__dirname}/templates/${templateName}`, {
91100
useAbsoluteTemplatePath: true,
92101
error: err,
93-
requestId: ctx.requestId
102+
supportEmail: config.supportEmail,
103+
requestId: ctx.requestId,
104+
t
94105
});
95106
}
96107

handlers/error/locales/en.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
400:
2+
title: Invalid request
3+
401:
4+
title: Authentication required
5+
description: Probably, you need to <a href="#" data-action-login>login</a>?
6+
7+
403:
8+
title: Access forbidden
9+
wrong_user: Perhaps, you logged in with the wrong user?
10+
login: Perhaps, you need to <a href="#" data-action-login>login</a>?
11+
12+
404:
13+
title: Page not found
14+
use_search: 'To find the page, you can use search:'
15+
search: Search
16+
use_top: …or top navigation.
17+
18+
500:
19+
title: Server error
20+
subject: "Error 500 at #{href}"
21+
description: 'We analyze errors, but you can speed up the process by reporting details to <a href="mailto:#{email}?subject=#{subject}">#{email}</a>.'
22+
23+
503:
24+
title: Service unavailable
25+
desc: Service unavailable, sorry, please try to access it later.

handlers/error/locales/ru.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
400:
2+
title: Некорректный запрос
3+
401:
4+
title: Требуется авторизация
5+
description: Возможно, вам нужно <a href="#" data-action-login>войти</a> в сайт?
6+
7+
403:
8+
title: Доступ запрещён
9+
wrong_user: Возможно, вы не под тем пользователем?
10+
login: Возможно, вам нужно войти на сайт?
11+
12+
404:
13+
title: Страница не найдена
14+
use_search: 'Для того, чтобы найти нужную вам страницу, вы можете воспользоваться поиском:'
15+
search: Найти
16+
use_top: …или верхней навигацией.
17+
18+
500:
19+
title: Ошибка на сервере
20+
subject: "Ошибка 500 на #{href}"
21+
description: 'Мы анализируем и исправляем возникающие ошибки, но вы можете ускорить этот процесс, сообщив подробности на <a href="mailto:#{email}?subject=#{subject}">#{email}</a>.'
22+
23+
503:
24+
title: Сервис недоступен
25+
desc: Извините, сервис недоступен, попытайтесь зайти позднее.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
extends /layouts/main
22

33
block append variables
4-
- let headTitle = 'Некорректный запрос';
5-
- let sitetoolbar = true;
4+
- let headTitle = t('error.400.title');
65

76
block content
87
+b.error
9-
+e('h1').type Некорректный запрос
8+
+e('h1').type= t('error.400.title')
109
+e.code 400
1110
if error.errors
1211

handlers/error/templates/401.pug

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extends /layouts/main
2+
3+
block append variables
4+
- let headTitle = t('error.401.title')
5+
6+
block content
7+
+b.error
8+
+e('h1').type= t('error.401.title')
9+
+e.code 401
10+
+e.text
11+
if error.description
12+
!= error.description
13+
else
14+
!= t('error.401.description')

handlers/error/templates/403.pug

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extends /layouts/main
2+
3+
block append variables
4+
- let headTitle = t('error.403.title')
5+
6+
block content
7+
+b.error
8+
+e('h1').type= t('error.403.title')
9+
+e.code 403
10+
+e.text
11+
if error.info
12+
!= error.info
13+
else if user
14+
= t('error.403.wrong_user')
15+
else
16+
= t('error.403.login')

handlers/error/templates/404.pug

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
extends /layouts/main
2+
3+
block append variables
4+
- let headTitle = t('error.404.title')
5+
6+
block content
7+
+b.error
8+
+e('h1').type= t('error.404.title')
9+
+e.code 404
10+
+e.text
11+
if error.info
12+
p= error.info
13+
14+
p= t('error.404.use_search')
15+
16+
+e.text
17+
+e('form').search(action="/search")
18+
+e.search-query-wrap
19+
+b('span').text-input.__search-query
20+
+e('input').control(type="text", name="query")
21+
+e.search-submit-wrap
22+
+b('button').button._action.__search-submit
23+
+e('span').text= t('error.404.search')
24+
+e.text= t('error.404.use_top')

0 commit comments

Comments
 (0)