Skip to content

Commit f9d31df

Browse files
committed
Added input validation to Indexer|CollectionEndpoint.get()
1 parent 0dc43c0 commit f9d31df

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

endpoints/generic/GenericCollectionEndpoint.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ export class GenericCollectionEndpoint<TEntity, TElementEndpoint extends Element
2626
* @param element The ID identifying the entity or an entity to extract the ID from.
2727
*/
2828
get(element: (TEntity | string)): TElementEndpoint {
29+
if (element == null) throw new Error("element must not be null or unspecified.");
30+
2931
let id: string;
3032
if (typeof element === "string") {
3133
id = element;
3234
} else {
3335
id = (element as any).id;
34-
if (id == null) throw new Error(`Element ${element} does not have an id property.`);
36+
if (id === undefined) throw new Error(`Element ${element} does not have an id property.`);
3537
}
38+
if (id == null || id === "") throw new Error("id must not be null or empty.");
3639

3740
return new this.elementEndpoint(this, this.linkTemplate("child", { id }));
3841
}

endpoints/generic/IndexerEndpoint.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class IndexerEndpoint<TElementEndpoint extends Endpoint> extends Endpoint
2121
* @param id The ID identifying the entity.
2222
*/
2323
get(id: string): TElementEndpoint {
24+
if (id == null || id === "") throw new Error("id must not be null, unspecified or empty.");
2425
return new this.elementEndpoint(this, this.linkTemplate("child", { id }));
2526
}
2627
}

0 commit comments

Comments
 (0)