-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.ts
More file actions
41 lines (38 loc) · 1.16 KB
/
errors.ts
File metadata and controls
41 lines (38 loc) · 1.16 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
import type { PolicyRule } from "./policy/types.js";
export class CodemodeError extends Error {
constructor(message: string) {
super(message);
this.name = this.constructor.name;
}
}
export class ApprovalRequiredError extends CodemodeError {
code = "APPROVAL_REQUIRED" as const;
namespace: string;
method: string;
path: string;
rule: PolicyRule;
approvalId: string;
approvalUrl?: string;
constructor(params: {
namespace: string;
method: string;
path: string;
rule: PolicyRule;
approvalId: string;
approvalUrl?: string;
}) {
const msg = [
`APPROVAL_REQUIRED: ${params.method} ${params.path} in namespace "${params.namespace}" requires approval.`,
params.rule.message ? `Rule: "${params.rule.message}"` : null,
params.approvalUrl ? `Request approval at: ${params.approvalUrl}` : null,
`After approval is granted, retry the same request.`,
].filter(Boolean).join("\n");
super(msg);
this.namespace = params.namespace;
this.method = params.method;
this.path = params.path;
this.rule = params.rule;
this.approvalId = params.approvalId;
this.approvalUrl = params.approvalUrl;
}
}