Skip to content

Commit

Permalink
#36 | Correct NotFound exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
himeshr committed Nov 25, 2022
1 parent 5e122b4 commit dfd6262
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.avni_integration_service.amrit.service;

import org.avni_integration_service.amrit.config.AmritEntityType;
import org.avni_integration_service.amrit.config.AmritErrorType;
import org.avni_integration_service.amrit.config.AmritMappingDbConstants;
import org.avni_integration_service.amrit.dto.AmritFetchIdentityResponse;
import org.avni_integration_service.amrit.repository.BeneficiaryRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.avni_integration_service.avni.domain.Subject;
import org.avni_integration_service.integration_data.repository.IntegrationSystemRepository;
import org.avni_integration_service.integration_data.repository.MappingMetaDataRepository;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;

Expand All @@ -29,8 +30,10 @@ public void createOrUpdateBornBirth(Subject subject, Enrolment enrolment) {
if (wasFetchOfAmritIdSuccessful(subject, true, true)) {
bornBirthRepository.createEvent(subject, enrolment, AmritBaseResponse.class);
}
} catch (HttpClientErrorException.NotFound e) {
beneficiaryRepository.createEvent(subject, null, AmritUpsertBeneficiaryResponse.class);
} catch (HttpClientErrorException e) {
if(e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
beneficiaryRepository.createEvent(subject, null, AmritUpsertBeneficiaryResponse.class);
}
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.avni_integration_service.avni.domain.Subject;
import org.avni_integration_service.integration_data.repository.IntegrationSystemRepository;
import org.avni_integration_service.integration_data.repository.MappingMetaDataRepository;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;

Expand All @@ -29,8 +30,10 @@ public void createOrUpdateCBAC(Subject subject, GeneralEncounter encounter) {
if (wasFetchOfAmritIdSuccessful(subject, true, true)) {
cBACRepository.createEvent(subject, encounter, AmritBaseResponse.class);
}
} catch (HttpClientErrorException.NotFound e) {
beneficiaryRepository.createEvent(subject, null, AmritUpsertBeneficiaryResponse.class);
} catch (HttpClientErrorException e) {
if(e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
beneficiaryRepository.createEvent(subject, null, AmritUpsertBeneficiaryResponse.class);
}
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.avni_integration_service.avni.domain.Household;
import org.avni_integration_service.integration_data.repository.IntegrationSystemRepository;
import org.avni_integration_service.integration_data.repository.MappingMetaDataRepository;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;

Expand All @@ -28,8 +29,10 @@ public void createOrUpdateHousehold(Household household) {
if (wasFetchOfAmritIdSuccessful(household.getMemberSubject(), true, true)) {
householdRepository.createEvent(household, AmritBaseResponse.class);
}
} catch (HttpClientErrorException.NotFound e) {
beneficiaryRepository.createEvent(household.getMemberSubject(), null, AmritUpsertBeneficiaryResponse.class);
} catch (HttpClientErrorException e) {
if(e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
beneficiaryRepository.createEvent(household.getMemberSubject(), null, AmritUpsertBeneficiaryResponse.class);
}
throw e;
}
}
Expand Down

0 comments on commit dfd6262

Please sign in to comment.