fix: Improve error messaging when file cannot be fetched for import

related #4006
This commit is contained in:
Tom Moor
2022-08-24 21:25:19 +02:00
parent a3d8e6c8fc
commit a869ab7609
2 changed files with 12 additions and 2 deletions

View File

@@ -1,5 +1,11 @@
import httpErrors from "http-errors";
export function InternalError(message = "Internal error") {
return httpErrors(500, message, {
id: "internal_error",
});
}
export function AuthenticationError(
message = "Authentication required",
redirectUrl = "/"

View File

@@ -1,9 +1,10 @@
import { S3 } from "aws-sdk";
import { truncate } from "lodash";
import { CollectionValidation } from "@shared/validations";
import attachmentCreator from "@server/commands/attachmentCreator";
import documentCreator from "@server/commands/documentCreator";
import { sequelize } from "@server/database/sequelize";
import { ValidationError } from "@server/errors";
import { InternalError, ValidationError } from "@server/errors";
import Logger from "@server/logging/Logger";
import {
User,
@@ -86,6 +87,9 @@ export default abstract class ImportTask extends BaseTask<Props> {
try {
Logger.info("task", `ImportTask fetching data for ${fileOperationId}`);
const data = await this.fetchData(fileOperation);
if (!data) {
throw InternalError("Failed to fetch data for import from storage.");
}
Logger.info("task", `ImportTask parsing data for ${fileOperationId}`);
const parsed = await this.parseData(data, fileOperation);
@@ -176,7 +180,7 @@ export default abstract class ImportTask extends BaseTask<Props> {
* @returns A promise that resolves to the structured data
*/
protected abstract parseData(
data: any,
data: S3.Body,
fileOperation: FileOperation
): Promise<StructuredImportData>;