♻️Added file path to all storage exceptions
This commit is contained in:
@@ -1,2 +1,10 @@
|
|||||||
export class FileNotFountException extends Error {}
|
export class FileNotFountException extends Error {
|
||||||
export class WriteFileException 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(
|
logger.error(
|
||||||
new OneOfStorageWriteOneFailedException(
|
new OneOfStorageWriteOneFailedException(
|
||||||
storageId,
|
storageId,
|
||||||
|
path,
|
||||||
`Error writing to storage ${storageId}`,
|
`Error writing to storage ${storageId}`,
|
||||||
(result as PromiseRejectedResult).reason,
|
(result as PromiseRejectedResult).reason,
|
||||||
),
|
),
|
||||||
@@ -85,7 +86,7 @@ export class OneOfStorageStrategy implements StorageConnectorAPI {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (errorsCount === this.storages.length) {
|
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(
|
const successResult = writeResults.filter(
|
||||||
@@ -111,13 +112,14 @@ export class OneOfStorageStrategy implements StorageConnectorAPI {
|
|||||||
logger.error(
|
logger.error(
|
||||||
new OneOfStorageReadOneFailedException(
|
new OneOfStorageReadOneFailedException(
|
||||||
storage.getId(),
|
storage.getId(),
|
||||||
|
path,
|
||||||
`Reading ${path} from storage ${storage} failed.`,
|
`Reading ${path} from storage ${storage} failed.`,
|
||||||
err,
|
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) {
|
} catch (e) {
|
||||||
throw new OneOfStorageReadOneFailedException(
|
throw new OneOfStorageReadOneFailedException(
|
||||||
storage.getId(),
|
storage.getId(),
|
||||||
|
path,
|
||||||
`Reading ${path} from storage ${storage} failed.`,
|
`Reading ${path} from storage ${storage} failed.`,
|
||||||
e,
|
e,
|
||||||
);
|
);
|
||||||
@@ -159,7 +162,7 @@ export class OneOfStorageStrategy implements StorageConnectorAPI {
|
|||||||
* Throw when read from one of the storages is filed.
|
* Throw when read from one of the storages is filed.
|
||||||
*/
|
*/
|
||||||
class StorageException extends Error {
|
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);
|
super(details, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ export default class StorageService extends TdriveService<StorageAPI> implements
|
|||||||
|
|
||||||
async read(path: string, options?: ReadOptions): Promise<Readable> {
|
async read(path: string, options?: ReadOptions): Promise<Readable> {
|
||||||
if (!(await this.exists(path, options))) {
|
if (!(await this.exists(path, options))) {
|
||||||
throw new FileNotFountException();
|
throw new FileNotFountException(path, "File doesn't exist");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||||
|
|||||||
Reference in New Issue
Block a user