public readonly code: string,
public readonly message: string,
public readonly param: string,
+ public readonly statusCode: number,
+ ) {}
+
+ getValidationError(): ValidationError | undefined {
+ if (this.type !== "invalid_request_error" || this.statusCode !== 400) {
+ return undefined;
+ }
+
+ return new ValidationError(this.code, this.message, this.param);
+ }
+}
+
+class ValidationError {
+ constructor(
+ public readonly code: string,
+ public readonly message: string,
+ public readonly param: string,
) {}
}
typeof json.message === "string" &&
typeof json.param === "string"
) {
- return apiResultFromError(new ApiError(json.type, json.code, json.message, json.param));
+ return apiResultFromError(new ApiError(json.type, json.code, json.message, json.param, response.status));
}
throw e;