diff --git a/libs/client/package.json b/libs/client/package.json
index cddbd2f..e372661 100644
--- a/libs/client/package.json
+++ b/libs/client/package.json
@@ -1,7 +1,7 @@
{
"name": "@fal-ai/serverless-client",
"description": "The fal serverless JS/TS client",
- "version": "0.3.1",
+ "version": "0.3.2",
"license": "MIT",
"repository": {
"type": "git",
diff --git a/libs/client/src/index.ts b/libs/client/src/index.ts
index 6bbf841..14a832b 100644
--- a/libs/client/src/index.ts
+++ b/libs/client/src/index.ts
@@ -4,4 +4,4 @@ export { withMiddleware, withProxy } from './middleware';
export type { RequestMiddleware } from './middleware';
export { ApiError, ValidationError } from './response';
export type { ResponseHandler } from './response';
-export type { QueueStatus } from './types';
+export type { QueueStatus, ValidationErrorInfo } from './types';
diff --git a/libs/client/src/response.ts b/libs/client/src/response.ts
index cf9cf6b..f972d94 100644
--- a/libs/client/src/response.ts
+++ b/libs/client/src/response.ts
@@ -20,20 +20,45 @@ export class ApiError
extends Error {
}
}
-export class ValidationError extends ApiError {
+type ValidationErrorBody = {
+ detail: ValidationErrorInfo[];
+};
+
+export class ValidationError extends ApiError {
constructor(args: ApiErrorArgs) {
super(args);
this.name = 'ValidationError';
}
+
+ get fieldErrors(): ValidationErrorInfo[] {
+ // NOTE: this is a hack to support both FastAPI/Pydantic errors
+ // and some custom 422 errors that might not be in the Pydantic format.
+ if (typeof this.body.detail === 'string') {
+ return [
+ {
+ loc: ['body'],
+ msg: this.body.detail,
+ type: 'value_error',
+ },
+ ];
+ }
+ return this.body.detail || [];
+ }
+
+ getFieldErrors(field: string): ValidationErrorInfo[] {
+ return this.fieldErrors.filter(
+ (error) => error.loc[error.loc.length - 1] === field
+ );
+ }
}
export async function defaultResponseHandler