Skip to content

Commit 3c3c30e

Browse files
committed
fixed pdf error handling and temporarily disabled pdf summaries
1 parent 52349de commit 3c3c30e

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

background.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ chrome.runtime.onMessage.addListener(
2727
}
2828

2929
if (request.action === "pdf" && request.url) {
30-
handlePDFLink(request.url, function(error, parsedText) {
30+
let sectionTitle = request.policyName;
31+
let domain = rootDomain(new URL(request.url).hostname);
32+
33+
handlePDFLink(request.url, domain, sectionTitle, function(error, parsedText) {
3134
if (error) {
3235
let sectionTitle = request.policyName;
3336
let domain = rootDomain(new URL(request.url).hostname);
@@ -55,14 +58,13 @@ chrome.runtime.onMessage.addListener(
5558
});
5659
})
5760
.catch(error => {
58-
console.warn('Error:', error);
5961
chrome.runtime.sendMessage({ showForm: true });
6062
chrome.storage.local.get(['loadingSummaries'], function (result) {
6163
let loadingSummaries = result.loadingSummaries || [];
6264
loadingSummaries = loadingSummaries.filter(summary => !(summary.title === sectionTitle && summary.domain === domain));
6365
chrome.storage.local.set({ loadingSummaries: loadingSummaries });
6466
});
65-
sendResponse({ error: 'An error occurred', errorMessage: error.toString() });
67+
sendResponse({ error: 'An error occurred' });
6668
});
6769
}
6870
});
@@ -248,25 +250,34 @@ function sendCheckboxNotification(domain) {
248250
// .then(data => data.html);
249251
// }
250252

251-
function handlePDFLink(pdfUrl, callback) {
253+
function handlePDFLink(pdfUrl, domain, sectionTitle, callback) {
252254
fetch('https://docdecoder.app/parsepdf', {
253255
method: 'POST',
254256
headers: {
255257
'Content-Type': 'application/json',
256258
},
257259
body: JSON.stringify({ url: pdfUrl })
258260
})
259-
.then(response => response.text())
261+
.then(response => {
262+
if (!response.ok) {
263+
throw new Error("We've temporarily disabled support for PDF summarisation whilst we work on a more efficient process for extracting PDF text. We're very sorry for the inconvenience, this feature will be back very soon.");
264+
}
265+
return response.text();
266+
})
260267
.then(parsedText => {
268+
console.log("Parsed text: " + parsedText);
261269
callback(null, parsedText); // First argument is error, which is null in this case
262270
})
263271
.catch(error => {
264-
handleSummaryError(domain, sectionTitle, error); // Store the error message
265-
reject(error); // Continue with the existing flow
272+
console.log("Error: " + error);
273+
handleSummaryError(domain, sectionTitle, error.toString()); // Store the error message
274+
callback(error, null); // Pass the error to the callback
266275
});
267276
}
268277

269278

279+
280+
270281
function fetchPageHTML(url, domain, sectionTitle) {
271282
return new Promise((resolve, reject) => {
272283
fetch(url)

0 commit comments

Comments
 (0)