-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathresponsevalidationerror.ts
More file actions
50 lines (45 loc) · 1.21 KB
/
responsevalidationerror.ts
File metadata and controls
50 lines (45 loc) · 1.21 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
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import { AttioError } from "./attioerror.js";
import { formatZodError } from "./sdkvalidationerror.js";
export class ResponseValidationError extends AttioError {
/**
* The raw value that failed validation.
*/
public readonly rawValue: unknown;
/**
* The raw message that failed validation.
*/
public readonly rawMessage: unknown;
constructor(
message: string,
extra: {
response: Response;
request: Request;
body: string;
cause: unknown;
rawValue: unknown;
rawMessage: unknown;
},
) {
super(message, extra);
this.name = "ResponseValidationError";
this.cause = extra.cause;
this.rawValue = extra.rawValue;
this.rawMessage = extra.rawMessage;
}
/**
* Return a pretty-formatted error message if the underlying validation error
* is a ZodError or some other recognized error type, otherwise return the
* default error message.
*/
public pretty(): string {
if (this.cause instanceof z.ZodError) {
return `${this.rawMessage}\n${formatZodError(this.cause)}`;
} else {
return this.toString();
}
}
}