Improved logging for client-aborted downloads

This commit is contained in:
grimsi
2022-08-10 21:15:58 +02:00
parent c196fd2cbc
commit 38bbdc7c57
2 changed files with 24 additions and 6 deletions
@@ -0,0 +1,7 @@
package de.grimsi.gameyfin.exceptions;
public class DownloadAbortedException extends RuntimeException {
public DownloadAbortedException() {
super();
}
}
@@ -2,18 +2,19 @@ package de.grimsi.gameyfin.service;
import de.grimsi.gameyfin.entities.Company; import de.grimsi.gameyfin.entities.Company;
import de.grimsi.gameyfin.entities.DetectedGame; import de.grimsi.gameyfin.entities.DetectedGame;
import de.grimsi.gameyfin.exceptions.DownloadAbortedException;
import de.grimsi.gameyfin.igdb.IgdbApiProperties; import de.grimsi.gameyfin.igdb.IgdbApiProperties;
import de.grimsi.gameyfin.repositories.DetectedGameRepository; import de.grimsi.gameyfin.repositories.DetectedGameRepository;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.ClientAbortException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.data.repository.core.RepositoryCreationException;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
@@ -88,7 +89,15 @@ public class DownloadService {
Path path = Path.of(game.getPath()); Path path = Path.of(game.getPath());
if (path.toFile().isDirectory()) { if (path.toFile().isDirectory()) {
try {
downloadFilesAsZip(path, outputStream); downloadFilesAsZip(path, outputStream);
} catch(DownloadAbortedException e) {
stopWatch.stop();
log.info("Download of game {} was aborted by client after {} seconds", game.getTitle(), (int) stopWatch.getTotalTimeSeconds());
return;
}
} else { } else {
downloadFile(path, outputStream); downloadFile(path, outputStream);
} }
@@ -99,7 +108,6 @@ public class DownloadService {
} }
public void downloadGameCoversFromIgdb() { public void downloadGameCoversFromIgdb() {
StopWatch stopWatch = new StopWatch(); StopWatch stopWatch = new StopWatch();
@@ -180,6 +188,9 @@ public class DownloadService {
}); });
zos.close(); zos.close();
} catch (ClientAbortException e) {
// Aborted downloads will be handled gracefully
throw new DownloadAbortedException();
} catch (IOException e) { } catch (IOException e) {
log.error("Error while zipping files:", e); log.error("Error while zipping files:", e);
} }