forked from lisong/code-push-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-error.ts
More file actions
44 lines (35 loc) · 1.23 KB
/
Copy pathapp-error.ts
File metadata and controls
44 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* eslint-disable max-classes-per-file */
export class AppError extends Error {
constructor(message: string | Error) {
super(message instanceof Error ? message.message : message);
this.name = 'AppError';
}
public status = 200;
}
/** i18n 에러 메시지 번역 포함 */
export class AppErrorI18n extends Error {
public readonly messageKey: string;
public readonly messageVars?: Record<string, any>;
constructor(messageKey: string, messageVars?: Record<string, any>) {
// Error.message에는 일단 key만 넣어둠 (실제 표현은 나중에 req.t로 처리)
super(messageKey);
this.messageKey = messageKey;
this.messageVars = messageVars;
Object.setPrototypeOf(this, new.target.prototype); // Error 상속시 필수 처리
this.name = 'AppErrorI18n';
}
}
export class NotFound extends AppError {
constructor(message?: string | Error) {
super(message || 'Not Found');
this.name = 'NotFoundError';
}
public status = 404;
}
export class Unauthorized extends AppError {
constructor(message?: string | Error) {
super(message || 'Unauthorized');
this.name = 'UnauthorizedError';
}
public status = 401;
}