133 lines
4.4 KiB
TypeScript
133 lines
4.4 KiB
TypeScript
import { FlowExecCtx } from "@core/flow.execution.context";
|
|
import { ERROR_CODES, type Err } from "@pkg/result";
|
|
import { getError } from "@pkg/logger";
|
|
|
|
export const fileErrors = {
|
|
dbError: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.DATABASE_ERROR,
|
|
message: "Database operation failed",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
|
|
fileNotFound: (fctx: FlowExecCtx, fileId: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.NOT_FOUND,
|
|
message: "File not found",
|
|
description:
|
|
"The requested file does not exist or you don't have access to it",
|
|
detail: `File ID: ${fileId}`,
|
|
}),
|
|
|
|
getFilesFailed: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.DATABASE_ERROR,
|
|
message: "Failed to fetch files",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
|
|
getFileFailed: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.DATABASE_ERROR,
|
|
message: "Failed to get file",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
|
|
createFileFailed: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.DATABASE_ERROR,
|
|
message: "Failed to create file record",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
|
|
updateFileFailed: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.DATABASE_ERROR,
|
|
message: "Failed to update file",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
|
|
deleteFilesFailed: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.DATABASE_ERROR,
|
|
message: "Failed to delete files",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
|
|
updateStatusFailed: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.DATABASE_ERROR,
|
|
message: "Failed to update file status",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
|
|
shareFileFailed: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.DATABASE_ERROR,
|
|
message: "Failed to share file",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
|
|
uploadFailed: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
message: "File upload failed",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
|
|
noFileMetadata: (fctx: FlowExecCtx): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
message: "Upload succeeded but no file metadata returned",
|
|
description: "Please try uploading again",
|
|
detail: "Storage service returned no file metadata",
|
|
}),
|
|
|
|
presignedUrlFailed: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
message: "Failed to generate presigned URL",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
|
|
noPresignedData: (fctx: FlowExecCtx): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
message: "Failed to generate presigned URL",
|
|
description: "Please try again later",
|
|
detail: "Storage service returned no presigned data",
|
|
}),
|
|
|
|
storageError: (fctx: FlowExecCtx, detail: string): Err =>
|
|
getError({
|
|
flowId: fctx.flowId,
|
|
code: ERROR_CODES.STORAGE_ERROR,
|
|
message: "Storage operation failed",
|
|
description: "Please try again later",
|
|
detail,
|
|
}),
|
|
};
|