Skip to content

Commit

Permalink
Merge pull request #338 from mild-blue/wrap-exceptions
Browse files Browse the repository at this point in the history
Wrap exceptions coming from the ISIN
  • Loading branch information
LukasForst authored Jun 18, 2021
2 parents 05a0722 + 26af04a commit 2a42e88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
27 changes: 17 additions & 10 deletions backend/src/main/kotlin/blue/mild/covid/vaxx/service/IsinService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class IsinService(
"?pcz=${encodeValue(configuration.pracovnik.pcz)}&pracovnikNrzpCislo=${encodeValue(configuration.pracovnik.nrzpCislo)}"

private companion object : KLogging() {
const val URL_GET_PATIENT_BY_PARAMETERS = "pacienti/VyhledatDleJmenoPrijmeniRc";
const val URL_GET_FOREIGNER_BY_INSURANCE_NUMBER = "pacienti/VyhledatCizinceDleCislaPojistence";
const val URL_GET_VACCINATIONS_BY_PATIENT_ID = "vakcinace/NacistVakcinacePacienta";
const val URL_UPDATE_PATIENT_INFO = "pacienti/AktualizujKontaktniUdajePacienta";
const val URL_CREATE_OR_CHANGE_VACCINATION = "vakcinace/VytvorNeboZmenVakcinaci";
const val URL_CREATE_OR_CHANGE_DOSE = "vakcinace/VytvorNeboZmenDavku";
const val URL_GET_PATIENT_BY_PARAMETERS = "pacienti/VyhledatDleJmenoPrijmeniRc"
const val URL_GET_FOREIGNER_BY_INSURANCE_NUMBER = "pacienti/VyhledatCizinceDleCislaPojistence"
const val URL_GET_VACCINATIONS_BY_PATIENT_ID = "vakcinace/NacistVakcinacePacienta"
const val URL_UPDATE_PATIENT_INFO = "pacienti/AktualizujKontaktniUdajePacienta"
const val URL_CREATE_OR_CHANGE_VACCINATION = "vakcinace/VytvorNeboZmenVakcinaci"
const val URL_CREATE_OR_CHANGE_DOSE = "vakcinace/VytvorNeboZmenDavku"
}

override suspend fun getPatientByParameters(
Expand Down Expand Up @@ -130,7 +130,10 @@ class IsinService(
true
}
}.getOrElse {
logger.error(it) {
logger.warn { "Data retrieval from ISIN - failure." }
val wrappingException =
Exception("An exception ${it.javaClass.canonicalName} was thrown! - ${it.message}\n${it.stackTraceToString()}")
logger.error(wrappingException) {
"Getting vaccinations from ISIN failed for patient with ISIN ID ${isinId}."
}
null
Expand Down Expand Up @@ -160,7 +163,10 @@ class IsinService(
logger.debug("Data obtained from ISIN: $contactInfoOut")
true
}.getOrElse {
logger.error(it) {
logger.warn { "Data retrieval from ISIN - failure." }
val wrappingException =
Exception("An exception ${it.javaClass.canonicalName} was thrown! - ${it.message}\n${it.stackTraceToString()}")
logger.error(wrappingException) {
"Exporting patient information to ISIN failed for patient with ISIN ID ${patient.isinId}"
}
false
Expand Down Expand Up @@ -204,7 +210,8 @@ class IsinService(
return false
}

val vaccinationExpirationInstant = vaccination.vaccineExpiration.atTime(LocalTime.MIDNIGHT).atZone(ZoneId.systemDefault()).toInstant();
val vaccinationExpirationInstant =
vaccination.vaccineExpiration.atTime(LocalTime.MIDNIGHT).atZone(ZoneId.systemDefault()).toInstant()

val defaultIndication = "J01"
val indication = if (patient.indication == null || patient.indication.isBlank())
Expand Down Expand Up @@ -311,7 +318,7 @@ class IsinService(
return url
}

private fun encodeValue(value: String): String? {
private fun encodeValue(value: String): String {
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString()).replace("+", "%20")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import blue.mild.covid.vaxx.security.ddos.CaptchaVerificationService
import blue.mild.covid.vaxx.security.ddos.RequestVerificationService
import blue.mild.covid.vaxx.service.DataCorrectnessService
import blue.mild.covid.vaxx.service.IsinRetryService
import blue.mild.covid.vaxx.service.IsinServiceInterface
import blue.mild.covid.vaxx.service.IsinService
import blue.mild.covid.vaxx.service.IsinServiceInterface
import blue.mild.covid.vaxx.service.IsinValidationService
import blue.mild.covid.vaxx.service.LocationService
import blue.mild.covid.vaxx.service.MailJetEmailService
Expand Down Expand Up @@ -139,7 +139,7 @@ fun DI.MainBuilder.registerClasses() {
val mapper = instance<ObjectMapper>()

@Suppress("MagicNumber") // carefully chosen constant
val isinTimeOutMillis = 15000L
val isinTimeOutMillis = 30000L
HttpClient(Apache) {
install(JsonFeature) {
serializer = JacksonSerializer(mapper)
Expand Down

0 comments on commit 2a42e88

Please sign in to comment.