File tree Expand file tree Collapse file tree 4 files changed +11
-34
lines changed Expand file tree Collapse file tree 4 files changed +11
-34
lines changed Original file line number Diff line number Diff line change @@ -136,12 +136,9 @@ open class Client {
136
136
/// @throws Exception
137
137
///
138
138
open func setEndpoint(_ endPoint: String) throws -> Client {
139
- guard endPoint.hasPrefix("http://") || endPoint.hasPrefix("https://") else {
139
+ if ! endPoint.hasPrefix("http://") && ! endPoint.hasPrefix("https://") {
140
140
throw {{spec .title | caseUcfirst }}Error(
141
- message: "Invalid endpoint URL: \(endPoint)",
142
- code: 0,
143
- type: "",
144
- response: ""
141
+ message: "Invalid endpoint URL: \(endPoint)"
145
142
)
146
143
}
147
144
@@ -162,12 +159,9 @@ open class Client {
162
159
/// @throws Exception
163
160
///
164
161
open func setEndpointRealtime(_ endPoint: String) throws -> Client {
165
- guard endPoint.hasPrefix("ws://") || endPoint.hasPrefix("wss://") else {
162
+ if ! endPoint.hasPrefix("ws://") && ! endPoint.hasPrefix("wss://") {
166
163
throw {{spec .title | caseUcfirst }}Error(
167
- message: "Invalid realtime endpoint URL: \(endPoint)",
168
- code: 0,
169
- type: "",
170
- response: ""
164
+ message: "Invalid realtime endpoint URL: \(endPoint)"
171
165
)
172
166
}
173
167
Original file line number Diff line number Diff line change @@ -132,13 +132,10 @@ open class Client {
132
132
/// @return Client
133
133
/// @throws Exception
134
134
///
135
- open func setEndpoint(_ endPoint: String) -> Client {
135
+ open func setEndpoint(_ endPoint: String) throws -> Client {
136
136
if !endPoint.hasPrefix("http://") && !endPoint.hasPrefix("https://") {
137
137
throw {{spec .title | caseUcfirst }}Error(
138
- message: "Invalid endpoint URL: \(endPoint)",
139
- code: 0,
140
- type: "",
141
- response: ""
138
+ message: "Invalid endpoint URL: \(endPoint)"
142
139
)
143
140
}
144
141
Original file line number Diff line number Diff line change @@ -330,12 +330,7 @@ class Client {
330
330
* @returns {this}
331
331
*/
332
332
setEndpoint(endpoint: string): this {
333
- try {
334
- const url = new URL(endpoint);
335
- if (url.protocol !== 'http:' && url.protocol !== 'https:') {
336
- throw new Error();
337
- }
338
- } catch {
333
+ if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
339
334
throw new {{spec .title | caseUcfirst }}Exception('Invalid endpoint URL: ' + endpoint);
340
335
}
341
336
@@ -353,13 +348,8 @@ class Client {
353
348
* @returns {this}
354
349
*/
355
350
setEndpointRealtime(endpointRealtime: string): this {
356
- try {
357
- const url = new URL(endpointRealtime);
358
- if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {
359
- throw new Error();
360
- }
361
- } catch {
362
- throw new {{spec .title | caseUcfirst }}Exception('Invalid endpoint URL: ' + endpointRealtime);
351
+ if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) {
352
+ throw new {{spec .title | caseUcfirst }}Exception('Invalid realtime endpoint URL: ' + endpointRealtime);
363
353
}
364
354
365
355
this.config.endpointRealtime = endpointRealtime;
Original file line number Diff line number Diff line change @@ -31,12 +31,8 @@ class Tests: XCTestCase {
31
31
print ( pingResult)
32
32
33
33
// reset configs
34
- try {
35
- client. setProject ( " console " )
36
- . setEndpointRealtime ( " ws://cloud.appwrite.io/v1 " )
37
- } catch {
38
- print ( error. localizedDescription)
39
- }
34
+ client. setProject ( " console " )
35
+ try client. setEndpointRealtime ( " ws://cloud.appwrite.io/v1 " )
40
36
41
37
let foo = Foo ( client)
42
38
let bar = Bar ( client)
You can’t perform that action at this time.
0 commit comments