Skip to content

Commit

Permalink
MODLD-582: Rework exception handling in search service
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiBordak authored and pkjacob committed Nov 22, 2024
1 parent 90387f9 commit 97b895c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public RequestProcessingException notFoundSourceRecordException(String idType, S
return requestProcessingException(notFoundError, "Source Record", idType, idValue, "Source Record storage");
}

public RequestProcessingException failedDependencyException(String message, Throwable t) {
return requestProcessingException(errorResponseConfig.getFailedDependency(), message, t.getMessage());
public RequestProcessingException failedDependencyException(String message, String reason) {
return requestProcessingException(errorResponseConfig.getFailedDependency(), message, reason);
}

private RequestProcessingException requestProcessingException(ErrorResponseConfig.Error error, String... arguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lombok.RequiredArgsConstructor;
import org.folio.linked.data.client.SearchClient;
import org.folio.linked.data.domain.dto.SearchResponseTotalOnly;
import org.folio.linked.data.exception.SearchException;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -36,11 +35,7 @@ public SearchResponseTotalOnly searchByLccnExcludingId(Collection<String> lccn,
}

private SearchResponseTotalOnly search(String query) {
try {
return searchClient.searchInstances(query).getBody();
} catch (Exception e) {
throw new SearchException("Unable to reach search service", e);
}
return searchClient.searchInstances(query).getBody();
}

private String getLccnQuery(Collection<String> lccnCol) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ private SearchResponseTotalOnly findInstanceWithLccn(List<String> lccn, String i
return instanceSearchService.searchByLccnExcludingId(lccn, inventoryId);
} catch (Exception e) {
log.error(e);
throw exceptionBuilder.failedDependencyException("Could not validate LCCN for duplicate", e);
throw exceptionBuilder.failedDependencyException(
"Could not validate LCCN for duplicate", "Unable to reach search service");
}
}

Expand All @@ -68,6 +69,7 @@ private boolean hasCurrentLccn(InstanceField instance) {

private List<String> getLccnValues(InstanceField instance) {
return getLccnRequest(instance)
.filter(LccnUtils::isCurrent)
.map(LccnRequest::getValue)
.flatMap(Collection::stream)
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.stream.Stream;
import org.folio.linked.data.client.SearchClient;
import org.folio.linked.data.domain.dto.SearchResponseTotalOnly;
import org.folio.linked.data.exception.SearchException;
import org.folio.spring.testing.type.UnitTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -45,7 +44,7 @@ void shouldReturnZeroTotalRecords_ifSearchClientThrowsNotFound() {
var lccn = List.of("");

// expect
assertThrows(SearchException.class, () -> searchService.searchByLccn(lccn));
assertThrows(FeignException.NotFound.class, () -> searchService.searchByLccn(lccn));
}

@Test
Expand Down

0 comments on commit 97b895c

Please sign in to comment.