fix: Improve error messaging when file cannot be fetched for import
related #4006
This commit is contained in:
@@ -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 = "/"
|
||||
|
||||
@@ -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>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user