More to the point: This does not work: while (cond...
# ktor
n
More to the point: This does not work: while (condition) { try { httpStatusCode = httpClient.get<HttpResponse> { method = HttpMethod.Get url("ActualURL") }.status.value } catch (exception: ConnectException) { delay(ppsConstant.delayTimeIntervalInSecondsForHealthCheck, TimeUnit.SECONDS) } } This works: while (condition) { try { httpStatusCode = httpClient.get<HttpResponse> { method = HttpMethod.Get url("ActualURL") }.status.value } catch (exception: ConnectException) { httpClient = HttpClient(CIO) delay(ppsConstant.delayTimeIntervalInSecondsForHealthCheck, TimeUnit.SECONDS) } }
a
@NGupta please surround multiline code with three backticks
n
This does not work:
Copy code
while (condition) {
	try {
		httpStatusCode = httpClient.get<HttpResponse> {
			method = HttpMethod.Get
			url("ActualURL")
		}.status.value
	} catch (exception: ConnectException) {
		delay(ppsConstant.delayTimeIntervalInSecondsForHealthCheck, TimeUnit.SECONDS)
	}
}
This works:
Copy code
while (condition) {
	try {
		httpStatusCode = httpClient.get<HttpResponse> {
			method = HttpMethod.Get
			url("ActualURL")
		}.status.value
	} catch (exception: ConnectException) {
		httpClient = HttpClient(CIO)
		delay(ppsConstant.delayTimeIntervalInSecondsForHealthCheck, TimeUnit.SECONDS)
	}
}
c
The second is not correct as a client need to be closed
Why doesn't work? what error do you see?
n
As I said second one is working. First one is not
a
@NGupta We need a little bit more information than does not work Any error messages?
n
absolutely. In the first snippet, after the catch block is executed, the execution goes into the try block and executes httpClient.get and stays there forever
In the second snippet, after the catch block is executed, the execution goes into the try block and executes httpClient.get and then either of the following occurs: 1: Again exception is thrown 2. A response is received and execution moves forward
I am basically trying to reuse the client after getting an error from the GET call
@Andreas Sinz @cy any updatess?
e
Hi, @NGupta. It looks like a bug for me. Could you file an issue?
n
sure..thanks ­čÖé
@e5l I have raised the bug: https://github.com/ktorio/ktor/issues/679