feat: friendly way to inform user there's an error (#12)

This commit is contained in:
鲁树人
2023-05-22 22:24:41 +01:00
parent 4aff3b7a07
commit 52d86e4601
8 changed files with 99 additions and 19 deletions

View File

@@ -1 +1,17 @@
export class UnsupportedSourceFile extends Error {}
export enum DecryptErrorType {
UNSUPPORTED_FILE = 'UNSUPPORTED_FILE',
UNKNOWN = 'UNKNOWN',
}
export class DecryptError extends Error {
code = DecryptErrorType.UNKNOWN;
toJSON() {
const { name, message, stack, code } = this;
return { name, message, stack, code };
}
}
export class UnsupportedSourceFile extends DecryptError {
code = DecryptErrorType.UNSUPPORTED_FILE;
}

View File

@@ -38,7 +38,7 @@ class DecryptCommandHandler {
}
}
throw new Error('could not decrypt file: no working decryptor found');
throw new UnsupportedSourceFile('could not decrypt file: no working decryptor found');
}
async decryptFile(crypto: CryptoBase) {