Improving upload logging

This commit is contained in:
Khalim Conn-Kowlessar 2026-04-20 14:04:06 +00:00
parent 542308f39f
commit 680935e1fa
3 changed files with 31 additions and 15 deletions

View file

@ -29,6 +29,7 @@ export async function GET(req: Request) {
s3FileBucket: uploadedFiles.s3FileBucket,
s3UploadTimestamp: uploadedFiles.s3UploadTimestamp,
fileType: uploadedFiles.fileType,
source: uploadedFiles.source,
uprn: uploadedFiles.uprn,
landlordPropertyId: uploadedFiles.landlordPropertyId,
measureName: uploadedFiles.measureName,
@ -41,6 +42,7 @@ export async function GET(req: Request) {
s3FileKey: row.s3FileKey,
s3FileBucket: row.s3FileBucket,
docType: row.fileType ?? "unknown",
source: row.source ?? null,
s3UploadTimestamp: row.s3UploadTimestamp.toISOString(),
uprn: row.uprn !== null ? String(row.uprn) : null,
landlordPropertyId: row.landlordPropertyId,

View file

@ -74,19 +74,32 @@ export async function syncRemovalRequestToHubSpot(params: {
export async function syncContractorDocUploadToHubSpot(params: {
hubspotDealId: string;
}): Promise<void> {
try {
const client = getHubSpotClient();
await client.crm.deals.basicApi.update(params.hubspotDealId, {
properties: {
contractor_document_upload_log: "Documents available - uploaded by contractor",
},
});
} catch (err) {
console.error("[HubSpot] syncContractorDocUploadToHubSpot failed", {
dealId: params.hubspotDealId,
error: err,
});
const maxAttempts = 3;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
const client = getHubSpotClient();
await client.crm.deals.basicApi.update(params.hubspotDealId, {
properties: {
contractor_document_upload_log: "Documents available - uploaded by contractor",
},
});
return;
} catch (err) {
const isReset =
err instanceof Error &&
"code" in err &&
(err as NodeJS.ErrnoException).code === "ECONNRESET";
if (isReset && attempt < maxAttempts) {
await new Promise((resolve) => setTimeout(resolve, 200 * attempt));
continue;
}
console.error("[HubSpot] syncContractorDocUploadToHubSpot failed", {
dealId: params.hubspotDealId,
attempt,
error: err,
});
return;
}
}
}

View file

@ -59,8 +59,9 @@ export async function uploadFileToS3({
});
if (!response.ok) {
console.error("Upload failed response:", response);
throw new Error("Network response was not ok");
const body = await response.text().catch(() => "(unreadable)");
console.error("Upload failed", { status: response.status, statusText: response.statusText, body });
throw new Error(`Upload failed: ${response.status} ${response.statusText}`);
}
} catch (error) {
console.error("Upload error:", error);