♻️Added file path to all storage exceptions

This commit is contained in:
Anton SHEPILOV
2024-12-19 19:02:27 +01:00
parent 0025964b68
commit c82787bc17
3 changed files with 17 additions and 6 deletions
@@ -1,2 +1,10 @@
export class FileNotFountException extends Error {}
export class WriteFileException extends Error {}
export class FileNotFountException extends Error {
constructor(readonly path: string, details: string) {
super(details);
}
}
export class WriteFileException extends Error {
constructor(readonly path: string, details: string) {
super(details);
}
}
@@ -77,6 +77,7 @@ export class OneOfStorageStrategy implements StorageConnectorAPI {
logger.error(
new OneOfStorageWriteOneFailedException(
storageId,
path,
`Error writing to storage ${storageId}`,
(result as PromiseRejectedResult).reason,
),
@@ -85,7 +86,7 @@ export class OneOfStorageStrategy implements StorageConnectorAPI {
}
});
if (errorsCount === this.storages.length) {
throw new WriteFileException(`Write ${path} failed for all storages`);
throw new WriteFileException(path, `Write ${path} failed for all storages`);
}
const successResult = writeResults.filter(
@@ -111,13 +112,14 @@ export class OneOfStorageStrategy implements StorageConnectorAPI {
logger.error(
new OneOfStorageReadOneFailedException(
storage.getId(),
path,
`Reading ${path} from storage ${storage} failed.`,
err,
),
);
}
}
throw new FileNotFountException(`Error reading ${path}`);
throw new FileNotFountException(path, `Error reading ${path}`);
};
/**
@@ -135,6 +137,7 @@ export class OneOfStorageStrategy implements StorageConnectorAPI {
} catch (e) {
throw new OneOfStorageReadOneFailedException(
storage.getId(),
path,
`Reading ${path} from storage ${storage} failed.`,
e,
);
@@ -159,7 +162,7 @@ export class OneOfStorageStrategy implements StorageConnectorAPI {
* Throw when read from one of the storages is filed.
*/
class StorageException extends Error {
constructor(readonly storageId: string, details: string, error: Error) {
constructor(readonly storageId: string, readonly path: string, details: string, error: Error) {
super(details, error);
}
}
@@ -104,7 +104,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements
async read(path: string, options?: ReadOptions): Promise<Readable> {
if (!(await this.exists(path, options))) {
throw new FileNotFountException();
throw new FileNotFountException(path, "File doesn't exist");
}
try {
// eslint-disable-next-line @typescript-eslint/no-this-alias