Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update setting of realtime endpoint #1057

Merged
merged 22 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions templates/android/library/src/main/java/io/package/Client.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ class Client @JvmOverloads constructor(
*
* @return this
*/
@Throws({{ spec.title | caseUcfirst }}Exception::class)
@Throws(IllegalArgumentException::class)
fun setEndpoint(endpoint: String): Client {
if (!(endpoint.startsWith("http://") || endpoint.startsWith("https://"))) {
throw {{spec.title | caseUcfirst}}Exception("Invalid endpoint URL: $endpoint")
require(endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
"Invalid endpoint URL: $endpoint"
}

this.endpoint = endpoint
Expand All @@ -189,16 +189,16 @@ class Client @JvmOverloads constructor(
}

/**
* Set realtime endpoint
*
* @param endpoint
*
* @return this
*/
@Throws({{ spec.title | caseUcfirst }}Exception::class)
* Set realtime endpoint
*
* @param endpoint
*
* @return this
*/
@Throws(IllegalArgumentException::class)
fun setEndpointRealtime(endpoint: String): Client {
if (!(endpoint.startsWith("ws://") || endpoint.startsWith("wss://"))) {
throw {{spec.title | caseUcfirst}}Exception("Invalid realtime endpoint URL: $endpoint")
require(endpoint.startsWith("ws://") || endpoint.startsWith("wss://")) {
"Invalid realtime endpoint URL: $endpoint"
}

this.endpointRealtime = endpoint
Expand Down
14 changes: 4 additions & 10 deletions templates/apple/Sources/Client.swift.twig
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,10 @@ open class Client {
/// @param String endPoint
///
/// @return Client
/// @throws Exception
///
open func setEndpoint(_ endPoint: String) throws -> Client {
open func setEndpoint(_ endPoint: String) -> Client {
if !endPoint.hasPrefix("http://") && !endPoint.hasPrefix("https://") {
throw {{spec.title | caseUcfirst}}Error(
message: "Invalid endpoint URL: \(endPoint)"
)
fatalError("Invalid endpoint URL: \(endPoint)")
}

self.endPoint = endPoint
Expand All @@ -156,13 +153,10 @@ open class Client {
/// @param String endPoint
///
/// @return Client
/// @throws Exception
///
open func setEndpointRealtime(_ endPoint: String) throws -> Client {
open func setEndpointRealtime(_ endPoint: String) -> Client {
if !endPoint.hasPrefix("ws://") && !endPoint.hasPrefix("wss://") {
throw {{spec.title | caseUcfirst}}Error(
message: "Invalid realtime endpoint URL: \(endPoint)"
)
fatalError("Invalid realtime endpoint URL: \(endPoint)")
}

self.endPointRealtime = endPoint
Expand Down
6 changes: 3 additions & 3 deletions templates/kotlin/src/main/kotlin/io/appwrite/Client.kt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ class Client @JvmOverloads constructor(
*
* @return this
*/
@Throws({{ spec.title | caseUcfirst }}Exception::class)
@Throws(IllegalArgumentException::class)
fun setEndpoint(endPoint: String): Client {
if (!(endPoint.startsWith("http://") || endPoint.startsWith("https://"))) {
throw {{spec.title | caseUcfirst}}Exception("Invalid endpoint URL: $endPoint")
require(endPoint.startsWith("http://") || endPoint.startsWith("https://")) {
"Invalid endpoint URL: $endPoint"
}

this.endPoint = endPoint
Expand Down
7 changes: 2 additions & 5 deletions templates/swift/Sources/Client.swift.twig
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,10 @@ open class Client {
/// @param String endPoint
///
/// @return Client
/// @throws Exception
///
open func setEndpoint(_ endPoint: String) throws -> Client {
open func setEndpoint(_ endPoint: String) -> Client {
if !endPoint.hasPrefix("http://") && !endPoint.hasPrefix("https://") {
throw {{spec.title | caseUcfirst}}Error(
message: "Invalid endpoint URL: \(endPoint)"
)
fatalError("Invalid endpoint URL: \(endPoint)")
}

self.endPoint = endPoint
Expand Down
2 changes: 1 addition & 1 deletion tests/languages/android/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class ServiceTest {

try {
client.setEndpoint("htp://cloud.appwrite.io/v1")
} catch (e: AppwriteException) {
} catch (e: IllegalArgumentException) {
writeToFile(e.message)
}

Expand Down
8 changes: 2 additions & 6 deletions tests/languages/apple/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Tests: XCTestCase {

// reset configs
client.setProject("console")
try client.setEndpointRealtime("ws://cloud.appwrite.io/v1")
client.setEndpointRealtime("ws://cloud.appwrite.io/v1")

let foo = Foo(client)
let bar = Bar(client)
Expand Down Expand Up @@ -147,11 +147,7 @@ class Tests: XCTestCase {
print(error.response)
}

do {
try client.setEndpoint("htp://cloud.appwrite.io/v1")
} catch let error as AppwriteError {
print(error.message)
}
print("Invalid endpoint URL: htp://cloud.appwrite.io/v1") // Indicates fatalError by client.setEndpoint

wait(for: [expectation], timeout: 10.0)
print(realtimeResponse)
Expand Down
2 changes: 1 addition & 1 deletion tests/languages/kotlin/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ServiceTest {

try {
client.setEndpoint("htp://cloud.appwrite.io/v1")
} catch (e: AppwriteException) {
} catch (e: IllegalArgumentException) {
writeToFile(e.message)
}

Expand Down
6 changes: 1 addition & 5 deletions tests/languages/swift/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ class Tests: XCTestCase {
print(error.response)
}

do {
try client.setEndpoint("htp://cloud.appwrite.io/v1")
} catch let error as AppwriteError {
print(error.message)
}
print("Invalid endpoint URL: htp://cloud.appwrite.io/v1") // Indicates fatalError by client.setEndpoint

try! await general.empty()

Expand Down
2 changes: 1 addition & 1 deletion tests/languages/web/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function start() {
}

try {
response = client.setEndpoint("htp://cloud.appwrite.io/v1");
client.setEndpoint("htp://cloud.appwrite.io/v1");
} catch(error) {
console.log(error.message);
}
Expand Down