-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathResult.ts
More file actions
31 lines (31 loc) · 808 Bytes
/
Result.ts
File metadata and controls
31 lines (31 loc) · 808 Bytes
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
export interface Result<T = any> {
status: number
body?: T
header?: {
eTag?: string
wwwAuthenticate?: string
}
}
export namespace Result {
export function is(value: any | Result): value is Result {
return (
typeof value == "object" &&
value &&
typeof value.status == "number" &&
(value.header == undefined ||
(typeof value.header == "object" && (value.header.eTag == undefined || typeof value.header.eTag == "string")))
)
}
export function hasBody(value: any | Result): value is Result & { body: any } {
return (
typeof value == "object" &&
value &&
typeof value.status == "number" &&
value.body != undefined &&
value.body != null
)
}
export function getBody(value: any | Result, fallback?: any): any {
return hasBody(value) ? value.body : fallback
}
}