LocalStorageAdapter delete catch block solved
This commit is contained in:
parent
631314dea8
commit
0c72d5a37c
1 changed files with 9 additions and 3 deletions
|
|
@ -3,7 +3,7 @@ import { promises as fs } from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
export class LocalStorageAdapter implements IStorageAdapter {
|
export class LocalStorageAdapter implements IStorageAdapter {
|
||||||
baseDir: string;
|
private baseDir: string;
|
||||||
|
|
||||||
constructor(baseDir: string) {
|
constructor(baseDir: string) {
|
||||||
this.baseDir = baseDir;
|
this.baseDir = baseDir;
|
||||||
|
|
@ -25,8 +25,14 @@ export class LocalStorageAdapter implements IStorageAdapter {
|
||||||
const fullPath = path.join(this.baseDir, key);
|
const fullPath = path.join(this.baseDir, key);
|
||||||
try {
|
try {
|
||||||
await fs.unlink(fullPath);
|
await fs.unlink(fullPath);
|
||||||
} catch {
|
} catch (error) {
|
||||||
//ignore error if file does not exist
|
const err = error as NodeJS.ErrnoException;
|
||||||
|
if (err?.code === "ENOENT" || err?.code === "ENOTDIR") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error(`Failed to delete file at ${fullPath}: `, error);
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue