mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
Refactor test files and remove unnecessary codes
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user