Skip to content
Prev Previous commit
Next Next commit
add error handling to uploadPdfToIA
  • Loading branch information
okerekechinweotito committed Dec 5, 2023
commit fbfb202864971923dc22e1c46202357f7ae9e1af
19 changes: 16 additions & 3 deletions bull/pdl-queue/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ async function uploadZipToIA(zip, metadata, byteLength, email, job) {
);
}

async function uploadPdfToIA(pdfBuffer, metadata, byteLength, email, job) {
async function uploadPdfToIA(
pdfBuffer,
metadata,
byteLength,
email,
job,
onError
) {
const bucketTitle = metadata.IAIdentifier;
const IAuri = `http://s3.us.archive.org/${bucketTitle}/${bucketTitle}.pdf`;
let headers = setHeaders(
Expand All @@ -177,14 +184,15 @@ async function uploadPdfToIA(pdfBuffer, metadata, byteLength, email, job) {
};
const readableStream = Readable.from(pdfBuffer);
readableStream.pipe(
request(options, async (error, response, body) => {
request(options, (error, response, body) => {
if (response.statusCode === 200) {
// EmailProducer(email, metadata.title, IAuri, true);
} else {
logger.log({
level: "error",
message: `IA Failure PDL ${body}`,
});
onError(true, body || error);
}
})
);
Expand All @@ -209,7 +217,12 @@ PDLQueue.process(async (job, done) => {
job.data.details,
byteLength,
job.data.details.email,
job
job,
(isError, error) => {
if (isError) {
done(new Error(error));
}
}
);
job.progress(100);
done(null, true);
Expand Down