fix(kobo): handle missing book when pulling kobo metadata (#473)

instead of an uncaught error, missing books should be treated as
a 404 not-found in the kobo metadata endpoint
This commit is contained in:
James Ward
2026-04-22 17:27:13 -04:00
committed by Zach Yale
parent d4bc8407d8
commit 28dd303e54
3 changed files with 34 additions and 6 deletions
@@ -124,12 +124,16 @@ public class KoboController {
@GetMapping("/v1/library/{bookId}/metadata")
public ResponseEntity<?> getBookMetadata(@Parameter(description = "Book ID") @PathVariable String bookId) {
if (StringUtils.isNumeric(bookId)) {
return ResponseEntity.ok(List.of(koboEntitlementService.getMetadataForBook(Long.parseLong(bookId), token)));
KoboBookMetadata metadata = koboEntitlementService.getMetadataForBook(Long.parseLong(bookId), token);
if (metadata != null) {
return ResponseEntity.ok(List.of(metadata));
}
} else if(isForwardingToKoboStore()) {
return koboServerProxy.proxyCurrentRequest(null, false);
} else {
throw ApiError.GENERIC_NOT_FOUND.createException("Not Found");
}
throw ApiError.GENERIC_NOT_FOUND.createException("Not Found");
}
@Operation(summary = "Get reading state", description = "Retrieve the reading state for a book.")
@@ -276,11 +276,14 @@ public class KoboEntitlementService {
}
public KoboBookMetadata getMetadataForBook(long bookId, String token) {
List<BookEntity> books = bookQueryService.findAllWithMetadataByIds(Set.of(bookId))
Optional<BookEntity> book = bookQueryService.findAllWithMetadataByIds(Set.of(bookId))
.stream()
.filter(koboCompatibilityService::isBookSupportedForKobo)
.toList();
return mapToKoboMetadata(books.getFirst(), token);
.findFirst();
return book
.map(bookEntity -> mapToKoboMetadata(bookEntity, token))
.orElse(null);
}
private KoboBookMetadata mapToKoboMetadata(BookEntity book, String token) {