-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mark darwin ktor engine as not supporting status codes
- Loading branch information
1 parent
83490b7
commit 7f15f0f
Showing
4 changed files
with
31 additions
and
38 deletions.
There are no files selected for viewing
60 changes: 24 additions & 36 deletions
60
...ktor/src/appleMain/kotlin/org/hildan/krossbow/websocket/ktor/HandshakeExceptionsDarwin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,30 @@ | ||
package org.hildan.krossbow.websocket.ktor | ||
|
||
import io.ktor.client.engine.darwin.DarwinHttpRequestException | ||
import kotlinx.cinterop.* | ||
import platform.Foundation.* | ||
internal actual fun extractHandshakeFailureDetails(handshakeException: Exception): HandshakeFailureDetails = | ||
genericFailureDetails(handshakeException) | ||
|
||
/* | ||
io.ktor.client.engine.darwin.DarwinHttpRequestException: | ||
Exception in http request: Error Domain=NSURLErrorDomain Code=-1011 "There was a bad response from the server." | ||
UserInfo={ | ||
NSErrorFailingURLStringKey=ws://localhost:49347/failHandshakeWithStatusCode/200, | ||
NSErrorFailingURLKey=ws://localhost:49347/failHandshakeWithStatusCode/200, | ||
_NSURLErrorWebSocketHandshakeFailureReasonKey=0, | ||
_NSURLErrorRelatedURLSessionTaskErrorKey=("LocalWebSocketTask <26F4D5BA-7104-4506-A521-DBC19B1CC2B0>.<1>"), | ||
_NSURLErrorFailingURLSessionTaskErrorKey=LocalWebSocketTask <26F4D5BA-7104-4506-A521-DBC19B1CC2B0>.<1>, | ||
NSLocalizedDescription=There was a bad response from the server. | ||
} | ||
*/ | ||
We cannot extract any response code from the exception. | ||
internal actual fun extractHandshakeFailureDetails(handshakeException: Exception): HandshakeFailureDetails = when (handshakeException) { | ||
is DarwinHttpRequestException -> extractHandshakeFailureDetails(handshakeException.origin) | ||
else -> genericFailureDetails(handshakeException) | ||
} | ||
The original error is almost the same for all response codes: | ||
io.ktor.client.engine.darwin.DarwinHttpRequestException: Exception in http request: Error Domain=NSURLErrorDomain Code=-1011 "There was a bad response from the server." | ||
// FIXME clean this up after investigation | ||
@OptIn(UnsafeNumber::class) | ||
private fun extractHandshakeFailureDetails(originError: NSError): HandshakeFailureDetails = HandshakeFailureDetails( | ||
statusCode = null, // TODO find out if we can get it from somewhere | ||
additionalInfo = """ | ||
domain=${originError.domain} | ||
code=${originError.code} | ||
description=${originError.description} | ||
userInfo=${originError.userInfo} | ||
underlyingErrors=${originError.underlyingErrors} | ||
localizedFailureReason=${originError.localizedFailureReason} | ||
localizedRecoveryOptions=${originError.localizedRecoveryOptions} | ||
helpAnchor=${originError.helpAnchor} | ||
recoveryAttempter=${originError.recoveryAttempter} | ||
originError to string: $originError | ||
""".trimIndent(), | ||
) | ||
NSError object attached to the DarwinHttpRequestException: | ||
{ | ||
code = -1011 | ||
description = Error Domain=NSURLErrorDomain Code=-1011 "There was a bad response from the server." UserInfo={NSErrorFailingURLStringKey=ws://localhost:49504/failHandshakeWithStatusCode/200, NSErrorFailingURLKey=ws://localhost:49504/failHandshakeWithStatusCode/200, _NSURLErrorWebSocketHandshakeFailureReasonKey=0, NSLocalizedDescription=There was a bad response from the server.} | ||
userInfo = { | ||
NSErrorFailingURLStringKey = ws://localhost:49347/failHandshakeWithStatusCode/200, | ||
NSErrorFailingURLKey = ws://localhost:49347/failHandshakeWithStatusCode/200, | ||
_NSURLErrorWebSocketHandshakeFailureReasonKey = 0, // sometimes different for tvOS | ||
_NSURLErrorRelatedURLSessionTaskErrorKey = ("LocalWebSocketTask <26F4D5BA-7104-4506-A521-DBC19B1CC2B0>.<1>"), | ||
_NSURLErrorFailingURLSessionTaskErrorKey = LocalWebSocketTask <26F4D5BA-7104-4506-A521-DBC19B1CC2B0>.<1>, | ||
NSLocalizedDescription=There was a bad response from the server. | ||
} | ||
underlyingErrors = [] | ||
localizedFailureReason = null | ||
localizedRecoveryOptions = null | ||
helpAnchor = null | ||
recoveryAttempter = null | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters