Skip to content

Commit

Permalink
fix(General): internal optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Udhayarajan committed Jul 16, 2023
1 parent f28877b commit f02747d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ plugins {
}

group = "io.github.udhayarajan"
version = "5.5.9.0.7"
version = "5.5.9.0.8"
//Version Naming incremented if "<NEW_FEATURE_ADDED>.<WORKED_ON_BUG>.<BETA_VERSION_COUNT>"
//Priority on incrementing Feature > BugFix > Beta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ class HttpInterfaceImpl(
setBody(TextContent(it.toJsonString(), ContentType.Application.Json))
}
}.bodyAsText()
client.close()

data
} catch (e: Exception) {
logger.error(
"postData() url=${url} header=${headers.toString()} & postData=${postData.toString()} Error:",
e
)
client.close()

throw e
}
}
Expand Down Expand Up @@ -124,22 +124,22 @@ class HttpInterfaceImpl(
val res = getLastPossibleRedirectedResponse(this, headers)
val isPageAvailable = res.status in acceptedStatusCode || res.status in redirectionStatusCode
logger.info("page availability = $isPageAvailable")
client.close()

return isPageAvailable
}
logger.warn("Unhandled in checkWebPage() status code=${status} for url=${url} with headers=${headers.toString()} & response=${bodyAsText()}")
false
}
client.close()

data
}
} catch (e: ClientRequestException) {
logger.error("checkWebPage() url=${url} header=${headers.toString()} ClientRequestException:", e)
client.close()

false
} catch (e: Exception) {
logger.error("checkWebPage() url=${url} header=${headers.toString()} GenericException:", e)
client.close()

false
}
}
Expand All @@ -159,41 +159,41 @@ class HttpInterfaceImpl(
}.run {
if (status == HttpStatusCode.OK) {
val data = bodyAsText()
client.close()

data
} else if (status in redirectionStatusCode) {
val data = getLastPossibleRedirectedResponse(this, headers).bodyAsText()
client.close()

data
} else if (url.contains("instagram") && status == HttpStatusCode.InternalServerError) {
client.close()

"{error:\"Invalid Cookies\"}"
} else if (status == HttpStatusCode.TooManyRequests) {
logger.warn("Unhandled in getData() TooManyRequest for url=${url} with headers=${headers.toString()} & response=${bodyAsText()}")
client.close()

"429"
} else {
logger.warn("Unhandled in getData() status code=${status} for url=${url} with headers=${headers.toString()} &\n response=${bodyAsText()}")
client.close()

null
}
}
} catch (e: ClientRequestException) {
logger.error("getData() url=${url} header=${headers.toString()} ClientRequestException:", e)
client.close()

null
} catch (e: SendCountExceedException) {
if (url.contains("instagram") && headers?.containsKey("Cookie") == true) {
client.close()

"{error:\"Invalid Cookies\"}"
} else {
logger.error("getData() url=${url} header=${headers.toString()} SendCountExceedException:", e)
client.close()

throw e
}
} catch (e: Exception) {
logger.error("getData() url=${url} header=${headers.toString()} Generic exception:", e)
client.close()

throw e
}
}
Expand All @@ -211,10 +211,10 @@ class HttpInterfaceImpl(
}
}
}
client.close()

response
} catch (e: Exception) {
client.close()

logger.error(
"getRawResponse() url=${url} header=${headers.toString()} Generic exception:",
e
Expand All @@ -236,12 +236,12 @@ class HttpInterfaceImpl(
}.run {
if (status == HttpStatusCode.OK) {
val data = this.headers["content-length"]?.toLong() ?: Long.MIN_VALUE
client.close()

data
} else Long.MIN_VALUE
}
} catch (e: Exception) {
client.close()

when (e) {
is HttpRequestTimeoutException, is ConnectTimeoutException, is SocketTimeoutException -> {
// handle the exception
Expand Down Expand Up @@ -278,7 +278,6 @@ class HttpInterfaceImpl(
}
}
}
nonRedirectingClient.close()
if (cacheResponse.request.url == tempResponse.request.url)
break
cacheResponse = tempResponse
Expand Down

0 comments on commit f02747d

Please sign in to comment.