-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiquidExtensionResult.ts
46 lines (42 loc) · 1.16 KB
/
LiquidExtensionResult.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
44
45
46
/**
* @hidden
*/
export interface LiquidExtensionResponse {
output?: string;
error?: string;
}
/**
* Result of {@link LiquidExtension.perform}. Clients should use the static {@link success} and {@link error} helper
* methods (as opposed to constructing manually).
*/
export class LiquidExtensionResult {
/**
* Builds a success response.
* @param output the resulting output (must be JSON-serializable)
*/
public static success(output: any) {
return new LiquidExtensionResult(true, output);
}
/**
* Builds an error response.
* @param message
*/
public static error(message: string) {
return new LiquidExtensionResult(false, undefined, message);
}
/**
* @hidden
* Use the static helper methods instead.
*/
public constructor(private success: boolean, private output?: any, private message?: string) { }
/**
* @hidden
* Used internally to get the complete response
*/
public getResponse(): LiquidExtensionResponse {
return {
output: this.success ? JSON.stringify(this.output === undefined ? null : this.output) : undefined,
error: this.success ? undefined : (this.message || 'unknown')
};
}
}