Refactor test files and remove unnecessary codes

This commit is contained in:
Caleb Okpara
2022-05-18 19:07:19 +00:00
parent 03002e9f32
commit 90b329e687
2 changed files with 1 additions and 16 deletions

View File

@@ -7,12 +7,6 @@ describe('Exception', () => {
}).toThrow('General exception error message');
});
test('should not accept invalid error code', () => {
expect(() => {
new Exception(700, 'error message');
}).toThrow('Invalid error code');
});
test('should return error message', () => {
expect(
new Exception(0, 'This code has not been implemented').message

View File

@@ -8,20 +8,11 @@ export default class Exception extends Error {
}
public set code(value: ExceptionCode) {
if (Exception.isValidCode(value)) {
this._code = value;
} else {
throw new Exception(400, 'Invalid error code');
}
this._code = value;
}
public constructor(code: ExceptionCode, message: string) {
super(message);
this.code = code;
}
private static isValidCode(code: number): boolean {
const exceptionCode: Array<number> = [0, 1, 2, 3, 5, 400];
return exceptionCode.includes(code);
}
}