Log geocode response in extracted data
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
This commit is contained in:
@@ -18,8 +18,10 @@ class GoogleGeocodingClient(
|
||||
) {
|
||||
private val logger = LoggerFactory.getLogger(GoogleGeocodingClient::class.java)
|
||||
|
||||
fun resolveCityState(pinCode: String): String? {
|
||||
if (apiKey.isBlank()) return null
|
||||
fun resolveCityState(pinCode: String): GeocodeResult {
|
||||
if (apiKey.isBlank()) {
|
||||
return GeocodeResult(null, null, "NO_API_KEY")
|
||||
}
|
||||
return try {
|
||||
val url = UriComponentsBuilder.fromUriString(baseUrl)
|
||||
.queryParam("components", "postal_code:$pinCode|country:IN")
|
||||
@@ -27,11 +29,12 @@ class GoogleGeocodingClient(
|
||||
.queryParam("key", apiKey)
|
||||
.toUriString()
|
||||
val response = restTemplate.getForEntity(url, String::class.java)
|
||||
val body = response.body ?: return null
|
||||
parseCityState(body)
|
||||
val body = response.body ?: return GeocodeResult(null, null, "EMPTY_BODY")
|
||||
val parsed = parseCityState(body)
|
||||
GeocodeResult(parsed, body, "OK")
|
||||
} catch (ex: Exception) {
|
||||
logger.warn("Geocoding failed: {}", ex.message)
|
||||
null
|
||||
GeocodeResult(null, null, "ERROR")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,3 +70,9 @@ class GoogleGeocodingClient(
|
||||
return listOfNotNull(preferredCity, state?.trim()?.ifBlank { null }).joinToString(", ")
|
||||
}
|
||||
}
|
||||
|
||||
data class GeocodeResult(
|
||||
val resolvedCityState: String?,
|
||||
val rawResponse: String?,
|
||||
val status: String?
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user