Skip to content

Commit ac31311

Browse files
authored
Merge pull request #1261 from appwrite/fix-typescript-setendpoint-validation
Fix TypeScript setEndpoint validation for undefined values
2 parents a13dfb9 + bfa2fb0 commit ac31311

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

templates/deno/src/client.ts.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export class Client {
4646
* @return this
4747
*/
4848
setEndpoint(endpoint: string): this {
49+
if (!endpoint || typeof endpoint !== 'string') {
50+
throw new {{spec.title | caseUcfirst}}Exception('Endpoint must be a valid string');
51+
}
52+
4953
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
5054
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
5155
}

templates/node/src/client.ts.twig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ class Client {
9696
* @returns {this}
9797
*/
9898
setEndpoint(endpoint: string): this {
99+
if (!endpoint || typeof endpoint !== 'string') {
100+
throw new {{spec.title | caseUcfirst}}Exception('Endpoint must be a valid string');
101+
}
102+
99103
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
100104
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
101105
}

templates/react-native/src/client.ts.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ class Client {
129129
* @returns {this}
130130
*/
131131
setEndpoint(endpoint: string): this {
132+
if (!endpoint || typeof endpoint !== 'string') {
133+
throw new {{spec.title | caseUcfirst}}Exception('Endpoint must be a valid string');
134+
}
135+
132136
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
133137
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
134138
}
@@ -147,6 +151,10 @@ class Client {
147151
* @returns {this}
148152
*/
149153
setEndpointRealtime(endpointRealtime: string): this {
154+
if (!endpointRealtime || typeof endpointRealtime !== 'string') {
155+
throw new {{spec.title | caseUcfirst}}Exception('Endpoint must be a valid string');
156+
}
157+
150158
if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) {
151159
throw new {{spec.title | caseUcfirst}}Exception('Invalid realtime endpoint URL: ' + endpointRealtime);
152160
}

templates/web/src/client.ts.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ class Client {
334334
* @returns {this}
335335
*/
336336
setEndpoint(endpoint: string): this {
337+
if (!endpoint || typeof endpoint !== 'string') {
338+
throw new {{spec.title | caseUcfirst}}Exception('Endpoint must be a valid string');
339+
}
340+
337341
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
338342
throw new {{spec.title | caseUcfirst}}Exception('Invalid endpoint URL: ' + endpoint);
339343
}
@@ -352,6 +356,10 @@ class Client {
352356
* @returns {this}
353357
*/
354358
setEndpointRealtime(endpointRealtime: string): this {
359+
if (!endpointRealtime || typeof endpointRealtime !== 'string') {
360+
throw new {{spec.title | caseUcfirst}}Exception('Endpoint must be a valid string');
361+
}
362+
355363
if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) {
356364
throw new {{spec.title | caseUcfirst}}Exception('Invalid realtime endpoint URL: ' + endpointRealtime);
357365
}

0 commit comments

Comments
 (0)