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 committed Nov 22, 2024
1 parent 90387f9 commit 12e8d5d
Show file tree
Hide file tree
Showing 4 changed files with 6 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 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 12e8d5d

Please sign in to comment.