-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathStatus.ts
43 lines (35 loc) · 1.22 KB
/
Status.ts
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
import { TStatus, TStatusCode } from '../../thrift/TCLIService_types';
import StatusError from '../errors/StatusError';
export default class Status {
private readonly status: TStatus;
constructor(status: TStatus) {
this.status = status;
}
public get isSuccess(): boolean {
const { statusCode } = this.status;
return statusCode === TStatusCode.SUCCESS_STATUS || statusCode === TStatusCode.SUCCESS_WITH_INFO_STATUS;
}
public get isExecuting(): boolean {
const { statusCode } = this.status;
return statusCode === TStatusCode.STILL_EXECUTING_STATUS;
}
public get isError(): boolean {
const { statusCode } = this.status;
return statusCode === TStatusCode.ERROR_STATUS || statusCode === TStatusCode.INVALID_HANDLE_STATUS;
}
public get info(): Array<string> {
return this.status.infoMessages || [];
}
public static assert(status: TStatus) {
const statusWrapper = new Status(status);
if (statusWrapper.isError) {
throw new StatusError(status);
}
}
public static success(info: Array<string> = []): Status {
return new Status({
statusCode: info.length > 0 ? TStatusCode.SUCCESS_WITH_INFO_STATUS : TStatusCode.SUCCESS_STATUS,
infoMessages: info,
});
}
}