(live-capture) Handle failed screenshot fetch in BrowserlessClient

Return an empty byte array when screenshot fetch fails, ensuring downstream processes are not impacted by null responses. Additionally, only attempt to upload the screenshot if the byte array is non-empty, preventing invalid data from being stored.
This commit is contained in:
Viktor Lofgren 2024-09-27 14:52:05 +02:00
parent ccf6b7caf3
commit 3dda8c228c
2 changed files with 4 additions and 1 deletions

View File

@ -74,6 +74,7 @@ public class BrowserlessClient implements AutoCloseable {
if (rsp.statusCode() >= 300) {
logger.info("Failed to fetch screenshot for {}, status {}", url, rsp.statusCode());
return new byte[0];
}
return rsp.body();

View File

@ -170,7 +170,9 @@ public class LiveCaptureGrpcService
byte[] pngBytes = client.screenshot(domain.toRootUrlHttps().toString(),
BrowserlessClient.GotoOptions.defaultValues(),
BrowserlessClient.ScreenshotOptions.defaultValues());
ScreenshotDbOperations.uploadScreenshot(conn, domain, pngBytes);
if (pngBytes.length > 0) {
ScreenshotDbOperations.uploadScreenshot(conn, domain, pngBytes);
}
} catch (Exception e) {
ScreenshotDbOperations.flagDomainAsFetched(conn, domain);
}