error handling

This commit is contained in:
Philipinho
2026-03-28 10:41:29 +00:00
parent c07f348b38
commit 4ebcbb71da
@@ -66,25 +66,25 @@ export class LocalDriver implements StorageDriver {
} }
async readStream(filePath: string): Promise<Readable> { async readStream(filePath: string): Promise<Readable> {
try { const fullPath = this._fullPath(filePath);
return createReadStream(this._fullPath(filePath)); if (!(await fs.pathExists(fullPath))) {
} catch (err) { throw new Error(`File not found: ${filePath}`);
throw new Error(`Failed to read file: ${(err as Error).message}`);
} }
return createReadStream(fullPath);
} }
async readRangeStream( async readRangeStream(
filePath: string, filePath: string,
range: { start: number; end: number }, range: { start: number; end: number },
): Promise<Readable> { ): Promise<Readable> {
try { const fullPath = this._fullPath(filePath);
return createReadStream(this._fullPath(filePath), { if (!(await fs.pathExists(fullPath))) {
start: range.start, throw new Error(`File not found: ${filePath}`);
end: range.end,
});
} catch (err) {
throw new Error(`Failed to read file: ${(err as Error).message}`);
} }
return createReadStream(fullPath, {
start: range.start,
end: range.end,
});
} }
async exists(filePath: string): Promise<boolean> { async exists(filePath: string): Promise<boolean> {