Skip to content

Commit 6ad194b

Browse files
committed
Improve error messages for invalid arguments and keys in Entries, Entry, and Query classes for better clarity and user guidance.
1 parent 7d8dce1 commit 6ad194b

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

src/lib/entries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class Entries extends BaseQuery {
150150
(this._queryParams['include[]'] as string[]).push(...(Array.isArray(value) ? value : [value]));
151151
});
152152
} else {
153-
console.error("Argument should be a String or an Array.");
153+
console.error("Invalid argument. Provide a string or an array and try again.");
154154
}
155155
return this;
156156
}

src/lib/entry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class Entry {
112112
(this._queryParams['include[]'] as string[]).push(...(Array.isArray(value) ? value : [value]));
113113
});
114114
} else {
115-
console.error("Argument should be a String or an Array.");
115+
console.error("Invalid argument. Provide a string or an array and try again.");
116116
}
117117
return this;
118118
}

src/lib/query.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class Query extends BaseQuery {
7373
additionalData?: object
7474
): Query {
7575
if (!this.isValidAlphanumeric(fieldUid)) {
76-
console.error("Invalid fieldUid:", fieldUid);
76+
console.error("Invalid fieldUid. Provide an alphanumeric field UID and try again.");
7777
return this;
7878
}
7979
if (queryOperation == QueryOperation.EQUALS) {
@@ -102,7 +102,7 @@ export class Query extends BaseQuery {
102102
*/
103103
regex(fieldUid: string, regexPattern: string, options?: string): Query {
104104
if (!this.isValidAlphanumeric(fieldUid)) {
105-
console.error("Invalid fieldUid:", fieldUid);
105+
console.error("Invalid fieldUid. Provide an alphanumeric field UID and try again.");
106106
return this;
107107
}
108108
if (!this.isValidRegexPattern(regexPattern)) {
@@ -226,11 +226,11 @@ export class Query extends BaseQuery {
226226
*/
227227
containedIn(key: string, value: (string | number | boolean)[]): Query {
228228
if (!this.isValidAlphanumeric(key)) {
229-
console.error("Invalid key:", key);
229+
console.error("Invalid key. Provide an alphanumeric key and try again.");
230230
return this;
231231
}
232232
if (!this.isValidValue(value)) {
233-
console.error("Invalid value:", value);
233+
console.error("Invalid value. Provide an array of strings, numbers, or booleans and try again.");
234234
return this;
235235
}
236236
this._parameters[key] = { '$in': value };
@@ -252,11 +252,11 @@ export class Query extends BaseQuery {
252252
*/
253253
notContainedIn(key: string, value: (string | number | boolean)[]): Query {
254254
if (!this.isValidAlphanumeric(key)) {
255-
console.error("Invalid key:", key);
255+
console.error("Invalid key. Provide an alphanumeric key and try again.");
256256
return this;
257257
}
258258
if (!this.isValidValue(value)) {
259-
console.error("Invalid value:", value);
259+
console.error("Invalid value. Provide an array of strings, numbers, or booleans and try again.");
260260
return this;
261261
}
262262
this._parameters[key] = { '$nin': value };
@@ -278,7 +278,7 @@ export class Query extends BaseQuery {
278278
*/
279279
exists(key: string): Query {
280280
if (!this.isValidAlphanumeric(key)) {
281-
console.error("Invalid key:", key);
281+
console.error("Invalid key. Provide an alphanumeric key and try again.");
282282
return this;
283283
}
284284
this._parameters[key] = { '$exists': true };
@@ -300,7 +300,7 @@ export class Query extends BaseQuery {
300300
*/
301301
notExists(key: string): Query {
302302
if (!this.isValidAlphanumeric(key)) {
303-
console.error("Invalid key:", key);
303+
console.error("Invalid key. Provide an alphanumeric key and try again.");
304304
return this;
305305
}
306306
this._parameters[key] = { '$exists': false };
@@ -367,11 +367,11 @@ export class Query extends BaseQuery {
367367
*/
368368
equalTo(key: string, value: string | number | boolean): Query {
369369
if (!this.isValidAlphanumeric(key)) {
370-
console.error("Invalid key:", key);
370+
console.error("Invalid key. Provide an alphanumeric key and try again.");
371371
return this;
372372
}
373373
if (typeof value !== 'string' && typeof value !== 'number') {
374-
console.error("Invalid value (expected string or number):", value);
374+
console.error("Invalid value. Provide a string or number and try again.");
375375
return this;
376376
}
377377
this._parameters[key] = value;
@@ -392,11 +392,11 @@ export class Query extends BaseQuery {
392392
*/
393393
notEqualTo(key: string, value: string | number | boolean): Query {
394394
if (!this.isValidAlphanumeric(key)) {
395-
console.error("Invalid key:", key);
395+
console.error("Invalid key. Provide an alphanumeric key and try again.");
396396
return this;
397397
}
398398
if (typeof value !== 'string' && typeof value !== 'number') {
399-
console.error("Invalid value (expected string or number):", value);
399+
console.error("Invalid value. Provide a string or number and try again.");
400400
return this;
401401
}
402402
this._parameters[key] = { '$ne': value };
@@ -418,7 +418,7 @@ export class Query extends BaseQuery {
418418
*/
419419
referenceIn(key: string, query: Query): Query {
420420
if (!this.isValidAlphanumeric(key)) {
421-
console.error("Invalid key:", key);
421+
console.error("Invalid key. Provide an alphanumeric key and try again.");
422422
return this;
423423
}
424424
this._parameters[key] = { '$in_query': query._parameters }
@@ -440,7 +440,7 @@ export class Query extends BaseQuery {
440440
*/
441441
referenceNotIn(key: string, query: Query): Query {
442442
if (!this.isValidAlphanumeric(key)) {
443-
console.error("Invalid key:", key);
443+
console.error("Invalid key. Provide an alphanumeric key and try again.");
444444
return this;
445445
}
446446
this._parameters[key] = { '$nin_query': query._parameters }
@@ -462,7 +462,7 @@ export class Query extends BaseQuery {
462462
*/
463463
tags(values: (string | number | boolean)[]): Query {
464464
if (!this.isValidValue(values)) {
465-
console.error("Invalid value:", values);
465+
console.error("Invalid value. Provide an array of strings, numbers, or booleans and try again.");
466466
return this;
467467
}
468468
this._parameters['tags'] = values;
@@ -484,7 +484,7 @@ export class Query extends BaseQuery {
484484
*/
485485
search(key: string): Query {
486486
if (!this.isValidAlphanumeric(key)) {
487-
console.error("Invalid key:", key);
487+
console.error("Invalid key. Provide an alphanumeric key and try again.");
488488
return this;
489489
}
490490
this._queryParams['typeahead'] = key
@@ -506,11 +506,11 @@ export class Query extends BaseQuery {
506506
*/
507507
lessThan(key: string, value: (string | number)): Query {
508508
if (!this.isValidAlphanumeric(key)) {
509-
console.error("Invalid key:", key);
509+
console.error("Invalid key. Provide an alphanumeric key and try again.");
510510
return this;
511511
}
512512
if (typeof value !== 'string' && typeof value !== 'number') {
513-
console.error("Invalid value (expected string or number):", value);
513+
console.error("Invalid value. Provide a string or number and try again.");
514514
return this;
515515
}
516516

@@ -533,11 +533,11 @@ export class Query extends BaseQuery {
533533
*/
534534
lessThanOrEqualTo(key: string, value: (string | number)): Query {
535535
if (!this.isValidAlphanumeric(key)) {
536-
console.error("Invalid key:", key);
536+
console.error("Invalid key. Provide an alphanumeric key and try again.");
537537
return this;
538538
}
539539
if (typeof value !== 'string' && typeof value !== 'number') {
540-
console.error("Invalid value (expected string or number):", value);
540+
console.error("Invalid value. Provide a string or number and try again.");
541541
return this;
542542
}
543543
this._parameters[key] = { '$lte': value };
@@ -559,11 +559,11 @@ export class Query extends BaseQuery {
559559
*/
560560
greaterThan(key: string, value: (string | number)): Query {
561561
if (!this.isValidAlphanumeric(key)) {
562-
console.error("Invalid key:", key);
562+
console.error("Invalid key. Provide an alphanumeric key and try again.");
563563
return this;
564564
}
565565
if (typeof value !== 'string' && typeof value !== 'number') {
566-
console.error("Invalid value (expected string or number):", value);
566+
console.error("Invalid value. Provide a string or number and try again.");
567567
return this;
568568
}
569569
this._parameters[key] = { '$gt': value };
@@ -585,11 +585,11 @@ export class Query extends BaseQuery {
585585
*/
586586
greaterThanOrEqualTo(key: string, value: (string | number)): Query {
587587
if (!this.isValidAlphanumeric(key)) {
588-
console.error("Invalid key:", key);
588+
console.error("Invalid key. Provide an alphanumeric key and try again.");
589589
return this;
590590
}
591591
if (typeof value !== 'string' && typeof value !== 'number') {
592-
console.error("Invalid value (expected string or number):", value);
592+
console.error("Invalid value. Provide a string or number and try again.");
593593
return this;
594594
}
595595
this._parameters[key] = { '$gte': value };

src/persistance/persistance-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class PersistanceStore {
3333
break;
3434
case 'customStorage':
3535
if (!store) {
36-
throw new TypeError('StorageType `customStorage` should have `storage`.');
36+
throw new TypeError('Missing storage for customStorage. Provide a storage object with get, set, and remove methods and try again.');
3737
} else {
3838
this.store = store;
3939
}

0 commit comments

Comments
 (0)