Spaces:
Build error
Build error
fix: bad snapshot in sideload should not throw directly
Browse files- src/api/crawler.ts +16 -2
src/api/crawler.ts
CHANGED
|
@@ -782,7 +782,14 @@ export class CrawlerHost extends RPCHost {
|
|
| 782 |
if (!sideLoaded.file) {
|
| 783 |
throw new ServiceBadAttemptError(`Remote server did not return a body: ${urlToCrawl}`);
|
| 784 |
}
|
| 785 |
-
let draftSnapshot = await this.snapshotFormatter.createSnapshotFromFile(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 786 |
if (sideLoaded.status == 200 && !sideLoaded.contentType.startsWith('text/html')) {
|
| 787 |
yield draftSnapshot;
|
| 788 |
return;
|
|
@@ -798,7 +805,14 @@ export class CrawlerHost extends RPCHost {
|
|
| 798 |
if (!proxyLoaded.file) {
|
| 799 |
throw new ServiceBadAttemptError(`Remote server did not return a body: ${urlToCrawl}`);
|
| 800 |
}
|
| 801 |
-
const proxySnapshot = await this.snapshotFormatter.createSnapshotFromFile(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 802 |
analyzed = await this.jsdomControl.analyzeHTMLTextLite(proxySnapshot.html);
|
| 803 |
if (proxyLoaded.status === 200 || analyzed.tokens >= 200) {
|
| 804 |
draftSnapshot = proxySnapshot;
|
|
|
|
| 782 |
if (!sideLoaded.file) {
|
| 783 |
throw new ServiceBadAttemptError(`Remote server did not return a body: ${urlToCrawl}`);
|
| 784 |
}
|
| 785 |
+
let draftSnapshot = await this.snapshotFormatter.createSnapshotFromFile(
|
| 786 |
+
urlToCrawl, sideLoaded.file, sideLoaded.contentType, sideLoaded.fileName
|
| 787 |
+
).catch((err) => {
|
| 788 |
+
if (err instanceof ApplicationError) {
|
| 789 |
+
return Promise.reject(new ServiceBadAttemptError(err.message));
|
| 790 |
+
}
|
| 791 |
+
return Promise.reject(err);
|
| 792 |
+
});
|
| 793 |
if (sideLoaded.status == 200 && !sideLoaded.contentType.startsWith('text/html')) {
|
| 794 |
yield draftSnapshot;
|
| 795 |
return;
|
|
|
|
| 805 |
if (!proxyLoaded.file) {
|
| 806 |
throw new ServiceBadAttemptError(`Remote server did not return a body: ${urlToCrawl}`);
|
| 807 |
}
|
| 808 |
+
const proxySnapshot = await this.snapshotFormatter.createSnapshotFromFile(
|
| 809 |
+
urlToCrawl, proxyLoaded.file, proxyLoaded.contentType, proxyLoaded.fileName
|
| 810 |
+
).catch((err) => {
|
| 811 |
+
if (err instanceof ApplicationError) {
|
| 812 |
+
return Promise.reject(new ServiceBadAttemptError(err.message));
|
| 813 |
+
}
|
| 814 |
+
return Promise.reject(err);
|
| 815 |
+
});
|
| 816 |
analyzed = await this.jsdomControl.analyzeHTMLTextLite(proxySnapshot.html);
|
| 817 |
if (proxyLoaded.status === 200 || analyzed.tokens >= 200) {
|
| 818 |
draftSnapshot = proxySnapshot;
|