Skip to content

Commit be1d746

Browse files
committed
chore: use fatal and illegalargument errors instead
1 parent 48f8edf commit be1d746

File tree

8 files changed

+24
-30
lines changed

8 files changed

+24
-30
lines changed

templates/android/library/src/main/java/io/package/Client.kt.twig

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ class Client @JvmOverloads constructor(
176176
*
177177
* @return this
178178
*/
179-
@Throws({{ spec.title | caseUcfirst }}Exception::class)
179+
@Throws(IllegalArgumentException::class)
180180
fun setEndpoint(endpoint: String): Client {
181-
if (!(endpoint.startsWith("http://") || endpoint.startsWith("https://"))) {
182-
throw {{spec.title | caseUcfirst}}Exception("Invalid endpoint URL: $endpoint")
181+
require(endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
182+
"Invalid endpoint URL: $endpoint"
183183
}
184184

185185
this.endpoint = endpoint
@@ -189,16 +189,16 @@ class Client @JvmOverloads constructor(
189189
}
190190

191191
/**
192-
* Set realtime endpoint
193-
*
194-
* @param endpoint
195-
*
196-
* @return this
197-
*/
198-
@Throws({{ spec.title | caseUcfirst }}Exception::class)
192+
* Set realtime endpoint
193+
*
194+
* @param endpoint
195+
*
196+
* @return this
197+
*/
198+
@Throws(IllegalArgumentException::class)
199199
fun setEndpointRealtime(endpoint: String): Client {
200-
if (!(endpoint.startsWith("ws://") || endpoint.startsWith("wss://"))) {
201-
throw {{spec.title | caseUcfirst}}Exception("Invalid realtime endpoint URL: $endpoint")
200+
require(endpoint.startsWith("ws://") || endpoint.startsWith("wss://")) {
201+
"Invalid realtime endpoint URL: $endpoint"
202202
}
203203

204204
this.endpointRealtime = endpoint

templates/apple/Sources/Client.swift.twig

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ open class Client {
137137
///
138138
open func setEndpoint(_ endPoint: String) throws -> Client {
139139
if !endPoint.hasPrefix("http://") && !endPoint.hasPrefix("https://") {
140-
throw {{spec.title | caseUcfirst}}Error(
141-
message: "Invalid endpoint URL: \(endPoint)"
142-
)
140+
fatalError("Invalid endpoint URL: \(endPoint)")
143141
}
144142

145143
self.endPoint = endPoint
@@ -160,9 +158,7 @@ open class Client {
160158
///
161159
open func setEndpointRealtime(_ endPoint: String) throws -> Client {
162160
if !endPoint.hasPrefix("ws://") && !endPoint.hasPrefix("wss://") {
163-
throw {{spec.title | caseUcfirst}}Error(
164-
message: "Invalid realtime endpoint URL: \(endPoint)"
165-
)
161+
fatalError("Invalid realtime endpoint URL: \(endPoint)")
166162
}
167163

168164
self.endPointRealtime = endPoint

templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ class Client @JvmOverloads constructor(
152152
*
153153
* @return this
154154
*/
155-
@Throws({{ spec.title | caseUcfirst }}Exception::class)
155+
@Throws(IllegalArgumentException::class)
156156
fun setEndpoint(endPoint: String): Client {
157-
if (!(endPoint.startsWith("http://") || endPoint.startsWith("https://"))) {
158-
throw {{spec.title | caseUcfirst}}Exception("Invalid endpoint URL: $endPoint")
157+
require(endPoint.startsWith("http://") || endPoint.startsWith("https://")) {
158+
"Invalid endpoint URL: $endPoint"
159159
}
160160

161161
this.endPoint = endPoint

templates/swift/Sources/Client.swift.twig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ open class Client {
134134
///
135135
open func setEndpoint(_ endPoint: String) throws -> Client {
136136
if !endPoint.hasPrefix("http://") && !endPoint.hasPrefix("https://") {
137-
throw {{spec.title | caseUcfirst}}Error(
138-
message: "Invalid endpoint URL: \(endPoint)"
139-
)
137+
fatalError("Invalid endpoint URL: \(endPoint)")
140138
}
141139

142140
self.endPoint = endPoint

tests/languages/android/Tests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class ServiceTest {
171171

172172
try {
173173
client.setEndpoint("htp://cloud.appwrite.io/v1")
174-
} catch (e: AppwriteException) {
174+
} catch (e: IllegalArgumentException) {
175175
writeToFile(e.message)
176176
}
177177

tests/languages/apple/Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ class Tests: XCTestCase {
149149

150150
do {
151151
try client.setEndpoint("htp://cloud.appwrite.io/v1")
152-
} catch let error as AppwriteError {
153-
print(error.message)
152+
} catch {
153+
print(error)
154154
}
155155

156156
wait(for: [expectation], timeout: 10.0)

tests/languages/kotlin/Tests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class ServiceTest {
138138

139139
try {
140140
client.setEndpoint("htp://cloud.appwrite.io/v1")
141-
} catch (e: AppwriteException) {
141+
} catch (e: IllegalArgumentException) {
142142
writeToFile(e.message)
143143
}
144144

tests/languages/swift/Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ class Tests: XCTestCase {
139139

140140
do {
141141
try client.setEndpoint("htp://cloud.appwrite.io/v1")
142-
} catch let error as AppwriteError {
143-
print(error.message)
142+
} catch {
143+
print(error)
144144
}
145145

146146
try! await general.empty()

0 commit comments

Comments
 (0)