Skip to content

Commit fc9539f

Browse files
Aschenscottinet
authored andcommitted
Remove local checks for arguments (#451)
## What does this PR do? `v6` version of #450 Remove the local check of the arguments since now we have specifics errors code sent by Kuzzle. ### Other changes - Add error codes `id` and `code` properties to `KuzzleError`
1 parent 8f2d44f commit fc9539f

File tree

13 files changed

+15
-1415
lines changed

13 files changed

+15
-1415
lines changed

src/KuzzleError.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class KuzzleError extends Error {
66

77
this.status = apiError.status;
88
this.stack = apiError.stack;
9+
this.id = apiError.id;
10+
this.code = apiError.code;
911

1012
// PartialError
1113
if (this.status === 206) {

src/controllers/auth.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ class AuthController extends BaseController {
3838
/**
3939
* Do not add the token for the checkToken route, to avoid getting a token error when
4040
* a developer simply wish to verify his token
41-
*
42-
* @param {object} request
41+
*
42+
* @param {object} request
4343
*/
4444
authenticateRequest (request) {
45-
if (!this.authenticationToken
45+
if ( !this.authenticationToken
4646
|| (request.controller === 'auth'
4747
&& (request.action === 'checkToken' || request.action === 'login'))
4848
) {
@@ -178,10 +178,6 @@ class AuthController extends BaseController {
178178
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
179179
*/
180180
login (strategy, credentials = {}, expiresIn = null) {
181-
if (typeof strategy !== 'string' || strategy === '') {
182-
throw new Error('Kuzzle.auth.login: strategy is required');
183-
}
184-
185181
const request = {
186182
strategy,
187183
expiresIn,

src/controllers/collection.js

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,17 @@ class CollectionController extends BaseController {
1111
super(kuzzle, 'collection');
1212
}
1313

14-
create (index, collection, body = {}, options = {}) {
15-
if (!index) {
16-
throw new Error('Kuzzle.collection.create: index is required');
17-
}
18-
if (!collection) {
19-
throw new Error('Kuzzle.collection.create: collection is required');
20-
}
21-
14+
create (index, collection, mappings = {}, options = {}) {
2215
return this.query({
2316
index,
2417
collection,
25-
body,
18+
body: mappings,
2619
action: 'create'
2720
}, options)
2821
.then(response => response.result);
2922
}
3023

3124
deleteSpecifications (index, collection, options = {}) {
32-
if (!index) {
33-
throw new Error('Kuzzle.collection.deleteSpecifications: index is required');
34-
}
35-
if (!collection) {
36-
throw new Error('Kuzzle.collection.deleteSpecifications: collection is required');
37-
}
38-
3925
return this.query({
4026
index,
4127
collection,
@@ -45,13 +31,6 @@ class CollectionController extends BaseController {
4531
}
4632

4733
exists (index, collection, options = {}) {
48-
if (!index) {
49-
throw new Error('Kuzzle.collection.exists: index is required');
50-
}
51-
if (!collection) {
52-
throw new Error('Kuzzle.collection.exists: collection is required');
53-
}
54-
5534
return this.query({
5635
index,
5736
collection,
@@ -61,13 +40,6 @@ class CollectionController extends BaseController {
6140
}
6241

6342
getMapping (index, collection, options = {}) {
64-
if (!index) {
65-
throw new Error('Kuzzle.collection.getMapping: index is required');
66-
}
67-
if (!collection) {
68-
throw new Error('Kuzzle.collection.getMapping: collection is required');
69-
}
70-
7143
return this.query({
7244
index,
7345
collection,
@@ -77,13 +49,6 @@ class CollectionController extends BaseController {
7749
}
7850

7951
getSpecifications (index, collection, options = {}) {
80-
if (!index) {
81-
throw new Error('Kuzzle.collection.getSpecifications: index is required');
82-
}
83-
if (!collection) {
84-
throw new Error('Kuzzle.collection.getSpecifications: collection is required');
85-
}
86-
8752
return this.query({
8853
index,
8954
collection,
@@ -93,10 +58,6 @@ class CollectionController extends BaseController {
9358
}
9459

9560
list (index, options = {}) {
96-
if (!index) {
97-
throw new Error('Kuzzle.collection.list: index is required');
98-
}
99-
10061
const request = {
10162
index,
10263
action: 'list',
@@ -115,8 +76,10 @@ class CollectionController extends BaseController {
11576
body,
11677
action: 'searchSpecifications'
11778
};
79+
11880
for (const opt of ['from', 'size', 'scroll']) {
11981
request[opt] = options[opt];
82+
12083
delete options[opt];
12184
}
12285

@@ -125,13 +88,6 @@ class CollectionController extends BaseController {
12588
}
12689

12790
truncate (index, collection, options = {}) {
128-
if (!index) {
129-
throw new Error('Kuzzle.collection.truncate: index is required');
130-
}
131-
if (!collection) {
132-
throw new Error('Kuzzle.collection.truncate: collection is required');
133-
}
134-
13591
return this.query({
13692
index,
13793
collection,
@@ -142,13 +98,6 @@ class CollectionController extends BaseController {
14298
}
14399

144100
updateMapping (index, collection, body, options = {}) {
145-
if (!index) {
146-
throw new Error('Kuzzle.collection.updateMapping: index is required');
147-
}
148-
if (!collection) {
149-
throw new Error('Kuzzle.collection.updateMapping: collection is required');
150-
}
151-
152101
return this.query({
153102
index,
154103
collection,
@@ -159,16 +108,6 @@ class CollectionController extends BaseController {
159108
}
160109

161110
updateSpecifications (index, collection, specifications, options = {}) {
162-
if (!index) {
163-
throw new Error('Kuzzle.collection.updateSpecifications: index is required');
164-
}
165-
if (!collection) {
166-
throw new Error('Kuzzle.collection.updateSpecifications: collection is required');
167-
}
168-
if (!specifications) {
169-
throw new Error('Kuzzle.collection.updateSpecifications: specifications are required');
170-
}
171-
172111
const body = {
173112
[index]: {
174113
[collection]: specifications
@@ -183,16 +122,6 @@ class CollectionController extends BaseController {
183122
}
184123

185124
validateSpecifications (index, collection, specifications, options = {}) {
186-
if (!index) {
187-
throw new Error('Kuzzle.collection.validateSpecifications: index is required');
188-
}
189-
if (!collection) {
190-
throw new Error('Kuzzle.collection.validateSpecifications: collection is required');
191-
}
192-
if (!specifications) {
193-
throw new Error('Kuzzle.collection.updateSpecifications: specifications are required');
194-
}
195-
196125
const body = {
197126
[index]: {
198127
[collection]: specifications

0 commit comments

Comments
 (0)