Skip to content

Commit 78ecd8a

Browse files
committed
Show config validation error
1 parent 745b633 commit 78ecd8a

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

bundle.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ packages:
1111
- lib
1212

1313
entries:
14-
client/fontello
14+
- client/fontello
15+
- server/fontello
1516

1617
lib:
1718
entries:

server/fontello/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
recursive: true
2+
public: false
3+
type:
4+
widget_i18n: i18n/*.yml
5+
widget_view: "*.jade"

server/fontello/font/generate.js

-20
This file was deleted.
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Handles requests for font generation
2+
//
3+
'use strict';
4+
5+
6+
const _ = require('lodash');
7+
const validator = require('is-my-json-valid');
8+
const config_schema = require('../_lib/config_schema');
9+
10+
11+
module.exports = function (N, apiPath) {
12+
const cfg_check = validator(config_schema, { verbose: true });
13+
14+
// Disable validation here to customize error message
15+
N.validate(apiPath, { additionalProperties: true, properties: {} });
16+
17+
18+
N.wire.before(apiPath, function validate(env) {
19+
if (cfg_check(env.params)) return;
20+
21+
let message = [ env.t('err_cfg_validation') ].concat(_.map(
22+
cfg_check.errors,
23+
e => `- ${e.field} ${e.message}`
24+
)).join('\n');
25+
26+
throw { code: N.io.CLIENT_ERROR, message };
27+
});
28+
29+
30+
N.wire.on(apiPath, function* request_font_generation(env) {
31+
let params = { config: env.params };
32+
33+
yield N.wire.emit('internal:fontello.font_build', params);
34+
env.res.id = params.fontId;
35+
});
36+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
en-US:
2+
err_cfg_validation: "Config validation error: "

0 commit comments

Comments
 (0)