Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ import kotlin.test.assertContains
class ApiUrlDiscoveryTest {
private val loginClient: WpLoginClient = WpLoginClient()

@Test
fun testLocalSite() = runTest {
assertEquals(
"http://localhost/wp-admin/authorize-application.php",
loginClient.apiDiscovery("http://localhost")
.assertSuccess().applicationPasswordsAuthenticationUrl.url()
)
}

@Test // Spec Example 1
fun testValidSiteWorksCorrectly() = runTest {
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import uniffi.wp_api.WpNetworkRequest
import uniffi.wp_api.WpNetworkResponse
import uniffi.wp_api.parseCertificate
import java.io.File
import java.net.ConnectException
import java.net.NoRouteToHostException
import java.net.UnknownHostException
import javax.net.ssl.HttpsURLConnection
Expand Down Expand Up @@ -130,7 +131,9 @@ class WpRequestExecutor(
)
}

@Suppress("ThrowsCount")
// We intentionally catch all exceptions to prevent UniFFI callback crashes.
// All exceptions are converted to proper Rust error types rather than being swallowed.
@Suppress("ThrowsCount", "TooGenericExceptionCaught", "SwallowedException")
private fun executeRequestSafely(
urlRequest: Request,
requestUrl: String,
Expand Down Expand Up @@ -162,6 +165,18 @@ class WpRequestExecutor(
throw requestExecutionFailedWith(RequestExecutionErrorReason.unknownHost(e))
} catch (e: NoRouteToHostException) {
throw requestExecutionFailedWith(RequestExecutionErrorReason.noRouteToHost(e))
} catch (e: ConnectException) {
throw requestExecutionFailedWith(
RequestExecutionErrorReason.HttpError(
reason = "Connection failed: ${e.localizedMessage}"
)
)
} catch (e: Exception) {
throw requestExecutionFailedWith(
RequestExecutionErrorReason.GenericError(
errorMessage = e.localizedMessage ?: e.toString()
)
)
}
}

Expand Down