kuzzle 2.17.3 → 2.17.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,54 +3,57 @@ import { ApplicationManager, Backend } from './index';
3
3
  import { CustomErrorDefinition } from '../../types';
4
4
  export declare class BackendErrors extends ApplicationManager {
5
5
  private domains;
6
- private subDomains;
7
6
  constructor(application: Backend);
8
7
  /**
9
8
  * Register a new standard KuzzleError
10
9
  *
10
+ * @param domain Domain name
11
11
  * @param subDomain Subdomain name
12
12
  * @param name Standard error name
13
13
  * @param definition Standard error definition
14
14
  *
15
15
  * @example
16
16
  * ```
17
- * app.errors.register('api', 'custom', {
17
+ * app.errors.register('app', 'api', 'custom', {
18
18
  * class: 'BadRequestError',
19
19
  * description: 'This is a custom error from API subdomain',
20
20
  * message: 'Custom API error: %s',
21
21
  * });
22
22
  * ```
23
23
  */
24
- register(subDomain: string, name: string, definition: CustomErrorDefinition): void;
24
+ register(domain: string, subDomain: string, name: string, definition: CustomErrorDefinition): void;
25
25
  /**
26
26
  * Get a standardized KuzzleError
27
27
  *
28
+ * @param domain Domain name
28
29
  * @param subDomain Subdomain name
29
30
  * @param name Standard error name
30
31
  * @param placeholders Other placeholder arguments
31
32
  *
32
- * @example throw app.errors.get('api', 'custom', 'Tbilisi');
33
+ * @example throw app.errors.get('app', 'api', 'custom', 'Tbilisi');
33
34
  *
34
35
  * @returns Standardized KuzzleError
35
36
  */
36
- get(subDomain: string, name: string, ...placeholders: any[]): KuzzleError;
37
+ get(domain: string, subDomain: string, name: string, ...placeholders: any[]): KuzzleError;
37
38
  /**
38
39
  * Get a standardized KuzzleError from an existing error to keep the stacktrace
39
40
  *
40
41
  * @param source Original error
42
+ * @param domain Domain name
41
43
  * @param subDomain Subdomain name
42
44
  * @param name Standard error name
43
45
  * @param placeholders Other placeholder arguments
44
46
  *
45
47
  * @returns Standardized KuzzleError
46
48
  */
47
- getFrom(source: Error, subDomain: string, name: string, ...placeholders: any[]): KuzzleError;
49
+ getFrom(source: Error, domain: string, subDomain: string, name: string, ...placeholders: any[]): KuzzleError;
48
50
  /**
49
- * Wrap an error manager on the subDomain
51
+ * Wrap an error manager on the domain and subDomain
50
52
  *
53
+ * @param domain Domain name
51
54
  * @param subDomain Subdomain to wrap to
52
55
  */
53
- wrap(subDomain: string): {
56
+ wrap(domain: string, subDomain: string): {
54
57
  get: (error: any, ...placeholders: any[]) => KuzzleError;
55
58
  getFrom: (source: any, error: any, ...placeholders: any[]) => KuzzleError;
56
59
  reject: (error: any, ...placeholders: any[]) => Promise<any>;
@@ -45,76 +45,80 @@ const index_1 = require("./index");
45
45
  class BackendErrors extends index_1.ApplicationManager {
46
46
  constructor(application) {
47
47
  super(application);
48
- this.domains = {
49
- app: {
50
- code: 9,
51
- subDomains: {},
52
- }
53
- };
54
- this.subDomains = 0;
48
+ this.domains = {};
55
49
  }
56
50
  /**
57
51
  * Register a new standard KuzzleError
58
52
  *
53
+ * @param domain Domain name
59
54
  * @param subDomain Subdomain name
60
55
  * @param name Standard error name
61
56
  * @param definition Standard error definition
62
57
  *
63
58
  * @example
64
59
  * ```
65
- * app.errors.register('api', 'custom', {
60
+ * app.errors.register('app', 'api', 'custom', {
66
61
  * class: 'BadRequestError',
67
62
  * description: 'This is a custom error from API subdomain',
68
63
  * message: 'Custom API error: %s',
69
64
  * });
70
65
  * ```
71
66
  */
72
- register(subDomain, name, definition) {
73
- if (!this.domains.app.subDomains[subDomain]) {
74
- this.domains.app.subDomains[subDomain] = {
75
- code: this.subDomains++,
67
+ register(domain, subDomain, name, definition) {
68
+ if (!this.domains[domain]) {
69
+ this.domains[domain] = {
70
+ code: Object.keys(this.domains).length,
71
+ subDomains: {},
72
+ };
73
+ }
74
+ if (!this.domains[domain].subDomains[subDomain]) {
75
+ this.domains[domain].subDomains[subDomain] = {
76
+ code: Object.keys(this.domains[domain].subDomains).length,
76
77
  errors: {},
77
78
  };
78
79
  }
79
- this.domains.app.subDomains[subDomain].errors[name] = {
80
- code: Object.keys(this.domains.app.subDomains[subDomain].errors).length,
80
+ this.domains[domain].subDomains[subDomain].errors[name] = {
81
+ code: Object.keys(this.domains[domain].subDomains[subDomain].errors).length,
81
82
  ...definition,
82
83
  };
83
84
  }
84
85
  /**
85
86
  * Get a standardized KuzzleError
86
87
  *
88
+ * @param domain Domain name
87
89
  * @param subDomain Subdomain name
88
90
  * @param name Standard error name
89
91
  * @param placeholders Other placeholder arguments
90
92
  *
91
- * @example throw app.errors.get('api', 'custom', 'Tbilisi');
93
+ * @example throw app.errors.get('app', 'api', 'custom', 'Tbilisi');
92
94
  *
93
95
  * @returns Standardized KuzzleError
94
96
  */
95
- get(subDomain, name, ...placeholders) {
96
- return kerror.rawGet(this.domains, 'app', subDomain, name, ...placeholders);
97
+ get(domain, subDomain, name, ...placeholders) {
98
+ return kerror.rawGet(this.domains, domain, subDomain, name, ...placeholders);
97
99
  }
98
100
  /**
99
101
  * Get a standardized KuzzleError from an existing error to keep the stacktrace
100
102
  *
101
103
  * @param source Original error
104
+ * @param domain Domain name
102
105
  * @param subDomain Subdomain name
103
106
  * @param name Standard error name
104
107
  * @param placeholders Other placeholder arguments
105
108
  *
106
109
  * @returns Standardized KuzzleError
107
110
  */
108
- getFrom(source, subDomain, name, ...placeholders) {
109
- return kerror.rawGetFrom(this.domains, source, 'app', subDomain, name, ...placeholders);
111
+ getFrom(source, domain, subDomain, name, ...placeholders) {
112
+ return kerror.rawGetFrom(this.domains, source, domain, subDomain, name, ...placeholders);
110
113
  }
111
114
  /**
112
- * Wrap an error manager on the subDomain
115
+ * Wrap an error manager on the domain and subDomain
113
116
  *
117
+ * @param domain Domain name
114
118
  * @param subDomain Subdomain to wrap to
115
119
  */
116
- wrap(subDomain) {
117
- return kerror.rawWrap(this.domains, 'app', subDomain);
120
+ wrap(domain, subDomain) {
121
+ return kerror.rawWrap(this.domains, domain, subDomain);
118
122
  }
119
123
  }
120
124
  exports.BackendErrors = BackendErrors;
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kuzzle",
3
- "version": "2.17.3",
3
+ "version": "2.17.4",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kuzzle",
3
3
  "author": "The Kuzzle Team <support@kuzzle.io>",
4
- "version": "2.17.3",
4
+ "version": "2.17.4",
5
5
  "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
6
6
  "bin": {
7
7
  "kuzzle": "bin/start-kuzzle-server"