-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathWebflowError.ts
More file actions
53 lines (46 loc) · 1.24 KB
/
WebflowError.ts
File metadata and controls
53 lines (46 loc) · 1.24 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
45
46
47
48
49
50
51
52
53
// This file was auto-generated by Fern from our API Definition.
import type * as core from "../core";
import { toJson } from "../core/json";
export class WebflowError extends Error {
public readonly statusCode?: number;
public readonly body?: unknown;
public readonly rawResponse?: core.RawResponse;
constructor({
message,
statusCode,
body,
rawResponse,
}: {
message?: string;
statusCode?: number;
body?: unknown;
rawResponse?: core.RawResponse;
}) {
super(buildMessage({ message, statusCode, body }));
Object.setPrototypeOf(this, WebflowError.prototype);
this.statusCode = statusCode;
this.body = body;
this.rawResponse = rawResponse;
}
}
function buildMessage({
message,
statusCode,
body,
}: {
message: string | undefined;
statusCode: number | undefined;
body: unknown | undefined;
}): string {
const lines: string[] = [];
if (message != null) {
lines.push(message);
}
if (statusCode != null) {
lines.push(`Status code: ${statusCode.toString()}`);
}
if (body != null) {
lines.push(`Body: ${toJson(body, undefined, 2)}`);
}
return lines.join("\n");
}