@zayne-labs/callapi 1.10.2 → 1.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,6 +57,6 @@ To do this, you first need to set your `script`'s type to `module`, then import
57
57
 
58
58
  <!-- Locked to a specific version -->
59
59
  <script type="module">
60
- import { callApi } from "https://esm.run/@zayne-labs/callapi@1.8.9";
60
+ import { callApi } from "https://esm.run/@zayne-labs/callapi@1.10.3";
61
61
  </script>
62
62
  ```
@@ -163,42 +163,6 @@ declare namespace StandardSchemaV1 {
163
163
  type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
164
164
  }
165
165
  //#endregion
166
- //#region src/error.d.ts
167
- type HTTPErrorDetails<TErrorData> = Pick<CallApiExtraOptions, "defaultHTTPErrorMessage"> & {
168
- errorData: TErrorData;
169
- response: Response;
170
- };
171
- declare class HTTPError<TErrorData = Record<string, unknown>> extends Error {
172
- errorData: HTTPErrorDetails<TErrorData>["errorData"];
173
- readonly httpErrorSymbol: symbol;
174
- name: "HTTPError";
175
- response: HTTPErrorDetails<TErrorData>["response"];
176
- constructor(errorDetails: HTTPErrorDetails<TErrorData>, errorOptions?: ErrorOptions);
177
- /**
178
- * @description Checks if the given error is an instance of HTTPError
179
- * @param error - The error to check
180
- * @returns true if the error is an instance of HTTPError, false otherwise
181
- */
182
- static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData>;
183
- }
184
- type ValidationErrorDetails = {
185
- issues: readonly StandardSchemaV1.Issue[];
186
- response: Response | null;
187
- };
188
- declare class ValidationError extends Error {
189
- errorData: ValidationErrorDetails["issues"];
190
- name: "ValidationError";
191
- response: ValidationErrorDetails["response"];
192
- readonly validationErrorSymbol: symbol;
193
- constructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions);
194
- /**
195
- * @description Checks if the given error is an instance of ValidationError
196
- * @param error - The error to check
197
- * @returns true if the error is an instance of ValidationError, false otherwise
198
- */
199
- static isError(error: unknown): error is ValidationError;
200
- }
201
- //#endregion
202
166
  //#region src/url.d.ts
203
167
  type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
204
168
  type RecordStyleParams = UnmaskType<Record<string, AllowedQueryParamValues>>;
@@ -403,6 +367,56 @@ type BaseCallApiSchemaAndConfig = {
403
367
  declare const fallBackRouteSchemaKey = ".";
404
368
  type FallBackRouteSchemaKey = typeof fallBackRouteSchemaKey;
405
369
  //#endregion
370
+ //#region src/error.d.ts
371
+ type HTTPErrorDetails<TErrorData> = Pick<CallApiExtraOptions, "defaultHTTPErrorMessage"> & {
372
+ errorData: TErrorData;
373
+ response: Response;
374
+ };
375
+ declare class HTTPError<TErrorData = Record<string, unknown>> extends Error {
376
+ errorData: HTTPErrorDetails<TErrorData>["errorData"];
377
+ readonly httpErrorSymbol: symbol;
378
+ name: "HTTPError";
379
+ response: HTTPErrorDetails<TErrorData>["response"];
380
+ constructor(errorDetails: HTTPErrorDetails<TErrorData>, errorOptions?: ErrorOptions);
381
+ /**
382
+ * @description Checks if the given error is an instance of HTTPError
383
+ * @param error - The error to check
384
+ * @returns true if the error is an instance of HTTPError, false otherwise
385
+ */
386
+ static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData>;
387
+ }
388
+ type LockedExtract<TUnion, TKey extends TUnion> = Extract<TUnion, TKey>;
389
+ type ValidationErrorDetails = {
390
+ /**
391
+ * The cause of the validation error.
392
+ *
393
+ * It's either the name the schema for which validation failed, or the name of the schema config option that led to the validation error.
394
+ */
395
+ issueCause: "unknown" | `schemaConfig-(${LockedExtract<keyof CallApiSchemaConfig, "strict">})` | keyof CallApiSchema;
396
+ /**
397
+ * The issues that caused the validation error.
398
+ */
399
+ issues: readonly StandardSchemaV1.Issue[];
400
+ /**
401
+ * The response from server, if any.
402
+ */
403
+ response: Response | null;
404
+ };
405
+ declare class ValidationError extends Error {
406
+ errorData: ValidationErrorDetails["issues"];
407
+ issueCause: ValidationErrorDetails["issueCause"];
408
+ name: "ValidationError";
409
+ response: ValidationErrorDetails["response"];
410
+ readonly validationErrorSymbol: symbol;
411
+ constructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions);
412
+ /**
413
+ * @description Checks if the given error is an instance of ValidationError
414
+ * @param error - The error to check
415
+ * @returns true if the error is an instance of ValidationError, false otherwise
416
+ */
417
+ static isError(error: unknown): error is ValidationError;
418
+ }
419
+ //#endregion
406
420
  //#region src/plugins.d.ts
407
421
  type PluginSetupContext<TPluginExtraOptions = unknown> = RequestContext & PluginExtraOptions<TPluginExtraOptions> & {
408
422
  initURL: string;
@@ -486,6 +500,7 @@ type PossibleHTTPError<TErrorData> = UnmaskType<{
486
500
  }>;
487
501
  type PossibleValidationError = UnmaskType<{
488
502
  errorData: ValidationError["errorData"];
503
+ issueCause: ValidationError["issueCause"];
489
504
  message: string;
490
505
  name: "ValidationError";
491
506
  originalError: ValidationError;
@@ -508,7 +523,7 @@ type ResultModeMapWithException<TData, TResponseType extends ResponseTypeUnion,
508
523
  all: CallApiResultSuccessVariant<TComputedData>;
509
524
  onlyData: CallApiResultSuccessVariant<TComputedData>["data"];
510
525
  };
511
- type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TThrowOnError extends ThrowOnErrorUnion = false> = TThrowOnError extends true ? ResultModeMapWithException<TData, TResponseType> : ResultModeMapWithoutException<TData, TErrorData, TResponseType>;
526
+ type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError> = TThrowOnError extends true ? ResultModeMapWithException<TData, TResponseType> : ResultModeMapWithoutException<TData, TErrorData, TResponseType>;
512
527
  type ResultModePlaceholder = null;
513
528
  type ResultModeUnion = keyof ResultModeMap | ResultModePlaceholder;
514
529
  type GetCallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = TErrorData extends false ? ResultModeMapWithException<TData, TResponseType>["onlyData"] : TErrorData extends false | undefined ? ResultModeMapWithException<TData, TResponseType>["onlyData"] : ResultModePlaceholder extends TResultMode ? ResultModeMap<TData, TErrorData, TResponseType, TThrowOnError>["all"] : TResultMode extends Exclude<ResultModeUnion, ResultModePlaceholder> ? ResultModeMap<TData, TErrorData, TResponseType, TThrowOnError>[TResultMode] : never;
@@ -807,7 +822,7 @@ type RequestContext = {
807
822
  };
808
823
  type ValidationErrorContext = UnmaskType<RequestContext & {
809
824
  /** Validation error containing details about what failed validation */
810
- error: ValidationError;
825
+ error: PossibleValidationError;
811
826
  /** HTTP response object if validation failed on response, null if on request */
812
827
  response: Response | null;
813
828
  }>;
@@ -822,7 +837,7 @@ type ResponseContext<TData, TErrorData> = UnmaskType<RequestContext & (Prettify<
822
837
  }>>)>;
823
838
  type RequestErrorContext = RequestContext & {
824
839
  /** Error that occurred during the request (network, timeout, etc.) */
825
- error: PossibleJavaScriptOrValidationError;
840
+ error: PossibleJavaScriptError;
826
841
  /** Always null for request errors since no response was received */
827
842
  response: null;
828
843
  };
@@ -1234,12 +1249,13 @@ type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorD
1234
1249
  resultMode?: TResultMode;
1235
1250
  };
1236
1251
  type ThrowOnErrorUnion = boolean;
1252
+ type ThrowOnErrorType<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TThrowOnError | ((context: ErrorContext<TErrorData>) => TThrowOnError);
1237
1253
  type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TErrorData extends false ? {
1238
1254
  throwOnError: true;
1239
1255
  } : TErrorData extends false | undefined ? {
1240
1256
  throwOnError?: true;
1241
1257
  } : {
1242
- throwOnError?: TThrowOnError | ((context: ErrorContext<TErrorData>) => TThrowOnError);
1258
+ throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
1243
1259
  };
1244
1260
  //#endregion
1245
1261
  //#region src/types/common.d.ts
@@ -1614,7 +1630,7 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
1614
1630
  * }
1615
1631
  * ```
1616
1632
  */
1617
- throwOnError?: TThrowOnError | ((context: ErrorContext<TErrorData>) => TThrowOnError);
1633
+ throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
1618
1634
  /**
1619
1635
  * Request timeout in milliseconds. Request will be aborted if it takes longer.
1620
1636
  *
@@ -1776,7 +1792,7 @@ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType,
1776
1792
  }) => TSchemaConfig);
1777
1793
  };
1778
1794
  type CallApiExtraOptionsForHooks = Hooks & Omit<CallApiExtraOptions, keyof Hooks>;
1779
- type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray> = (CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>) | ((context: {
1795
+ type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray> = (CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>) | ((instanceConfig: {
1780
1796
  initURL: string;
1781
1797
  options: CallApiExtraOptions;
1782
1798
  request: CallApiRequestOptions;
@@ -1786,4 +1802,4 @@ type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TR
1786
1802
  type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
1787
1803
  //#endregion
1788
1804
  export { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey };
1789
- //# sourceMappingURL=common-ChqKsMZ2.d.ts.map
1805
+ //# sourceMappingURL=common-Bk1Hh1hR.d.ts.map
@@ -1,4 +1,4 @@
1
- import { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey } from "./common-ChqKsMZ2.js";
1
+ import { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey } from "./common-Bk1Hh1hR.js";
2
2
 
3
3
  //#region src/createFetchClient.d.ts
4
4
 
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { HTTPError, ValidationError, createCombinedSignal, createTimeoutSignal, defineEnum, deterministicHashFn, extraOptionDefaults, getBody, getFetchImpl, getHeaders, isArray, isBoolean, isFunction, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isString, isValidationErrorInstance, requestOptionDefaults, splitBaseConfig, splitConfig, toArray, toQueryString, waitFor } from "./utils-zvYT8TK8.js";
1
+ import { HTTPError, ValidationError, createCombinedSignal, createTimeoutSignal, defineEnum, deterministicHashFn, extraOptionDefaults, getBody, getFetchImpl, getHeaders, isArray, isBoolean, isFunction, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isString, isValidationErrorInstance, requestOptionDefaults, splitBaseConfig, splitConfig, toArray, toQueryString, waitFor } from "./utils-Bm4Dvem6.js";
2
2
 
3
3
  //#region src/result.ts
4
4
  const getResponseType = (response, parser) => ({
@@ -66,6 +66,7 @@ const resolveErrorResult = (error, info) => {
66
66
  data: null,
67
67
  error: {
68
68
  errorData,
69
+ issueCause: error.issueCause,
69
70
  message,
70
71
  name: "ValidationError",
71
72
  originalError: error
@@ -341,12 +342,15 @@ const handleValidatorFunction = async (validator, inputData) => {
341
342
  };
342
343
  }
343
344
  };
344
- const standardSchemaParser = async (schema, inputData, response) => {
345
+ const standardSchemaParser = async (fullSchema, schemaName, inputData, response) => {
346
+ const schema = fullSchema?.[schemaName];
347
+ if (!schema) return inputData;
345
348
  const result = isFunction(schema) ? await handleValidatorFunction(schema, inputData) : await schema["~standard"].validate(inputData);
346
349
  if (result.issues) throw new ValidationError({
350
+ issueCause: schemaName,
347
351
  issues: result.issues,
348
352
  response: response ?? null
349
- }, { cause: result.issues });
353
+ });
350
354
  return result.value;
351
355
  };
352
356
  const routeKeyMethods = defineEnum([
@@ -356,10 +360,10 @@ const routeKeyMethods = defineEnum([
356
360
  "post",
357
361
  "put"
358
362
  ]);
359
- const handleSchemaValidation = async (schema, validationOptions) => {
363
+ const handleSchemaValidation = async (fullSchema, schemaName, validationOptions) => {
360
364
  const { inputValue, response, schemaConfig } = validationOptions;
361
- if (!schema || schemaConfig?.disableRuntimeValidation) return inputValue;
362
- return await standardSchemaParser(schema, inputValue, response);
365
+ if (schemaConfig?.disableRuntimeValidation) return inputValue;
366
+ return await standardSchemaParser(fullSchema, schemaName, inputValue, response);
363
367
  };
364
368
  const extraOptionsToBeValidated = [
365
369
  "meta",
@@ -368,15 +372,15 @@ const extraOptionsToBeValidated = [
368
372
  ];
369
373
  const handleExtraOptionsValidation = async (validationOptions) => {
370
374
  const { options, schema, schemaConfig } = validationOptions;
371
- const validationResultArray = await Promise.all(extraOptionsToBeValidated.map((propertyKey) => handleSchemaValidation(schema?.[propertyKey], {
372
- inputValue: options[propertyKey],
375
+ const validationResultArray = await Promise.all(extraOptionsToBeValidated.map((schemaName) => handleSchemaValidation(schema, schemaName, {
376
+ inputValue: options[schemaName],
373
377
  schemaConfig
374
378
  })));
375
379
  const validatedResultObject = {};
376
- for (const [index, propertyKey] of extraOptionsToBeValidated.entries()) {
380
+ for (const [index, schemaName] of extraOptionsToBeValidated.entries()) {
377
381
  const validationResult = validationResultArray[index];
378
382
  if (validationResult === void 0) continue;
379
- validatedResultObject[propertyKey] = validationResult;
383
+ validatedResultObject[schemaName] = validationResult;
380
384
  }
381
385
  return validatedResultObject;
382
386
  };
@@ -387,8 +391,8 @@ const requestOptionsToBeValidated = [
387
391
  ];
388
392
  const handleRequestOptionsValidation = async (validationOptions) => {
389
393
  const { requestOptions, schema, schemaConfig } = validationOptions;
390
- const validationResultArray = await Promise.all(requestOptionsToBeValidated.map((propertyKey) => handleSchemaValidation(schema?.[propertyKey], {
391
- inputValue: requestOptions[propertyKey],
394
+ const validationResultArray = await Promise.all(requestOptionsToBeValidated.map((schemaName) => handleSchemaValidation(schema, schemaName, {
395
+ inputValue: requestOptions[schemaName],
392
396
  schemaConfig
393
397
  })));
394
398
  const validatedResultObject = {};
@@ -410,7 +414,8 @@ const handleConfigValidation = async (validationOptions) => {
410
414
  baseExtraOptions,
411
415
  extraOptions
412
416
  });
413
- if (!currentRouteSchema && resolvedSchemaConfig?.strict === true) throw new ValidationError({
417
+ if (resolvedSchemaConfig?.strict === true && !currentRouteSchema) throw new ValidationError({
418
+ issueCause: "schemaConfig-(strict)",
414
419
  issues: [{ message: `Strict Mode - No schema found for route '${currentRouteSchemaKey}' ` }],
415
420
  response: null
416
421
  });
@@ -601,7 +606,7 @@ const createRetryStrategy = (ctx) => {
601
606
  const retryMethods = new Set(options.retryMethods ?? options.retry?.methods ?? extraOptionDefaults().retryMethods);
602
607
  const includesMethod = isString(ctx.request.method) && retryMethods.size > 0 ? retryMethods.has(ctx.request.method) : true;
603
608
  const retryStatusCodes = new Set(options.retryStatusCodes ?? options.retry?.statusCodes ?? extraOptionDefaults().retryStatusCodes);
604
- const includesStatusCodes = Boolean(ctx.response) && retryStatusCodes.size > 0 ? retryStatusCodes.has(ctx.response.status) : true;
609
+ const includesStatusCodes = ctx.response != null && retryStatusCodes.size > 0 ? retryStatusCodes.has(ctx.response.status) : true;
605
610
  return includesMethod && includesStatusCodes;
606
611
  };
607
612
  return {
@@ -815,7 +820,7 @@ const createFetchClient = (initBaseConfig = {}) => {
815
820
  const shouldCloneResponse = resolvedDedupeStrategy === "defer" || options.cloneResponse;
816
821
  if (!response.ok) {
817
822
  const errorData = await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser);
818
- const validErrorData = await handleSchemaValidation(resolvedSchema?.errorData, {
823
+ const validErrorData = await handleSchemaValidation(resolvedSchema, "errorData", {
819
824
  inputValue: errorData,
820
825
  response,
821
826
  schemaConfig: resolvedSchemaConfig
@@ -827,7 +832,7 @@ const createFetchClient = (initBaseConfig = {}) => {
827
832
  }, { cause: validErrorData });
828
833
  }
829
834
  const successData = await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser);
830
- const validSuccessData = await handleSchemaValidation(resolvedSchema?.data, {
835
+ const validSuccessData = await handleSchemaValidation(resolvedSchema, "data", {
831
836
  inputValue: successData,
832
837
  response,
833
838
  schemaConfig: resolvedSchemaConfig
@@ -862,7 +867,7 @@ const createFetchClient = (initBaseConfig = {}) => {
862
867
  request,
863
868
  response: errorDetails.response
864
869
  };
865
- const shouldThrowOnError = isFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError;
870
+ const shouldThrowOnError = Boolean(isFunction(options.throwOnError) ? options.throwOnError(errorContext) : options.throwOnError);
866
871
  const hookInfo = {
867
872
  errorInfo,
868
873
  shouldThrowOnError
@@ -887,11 +892,7 @@ const createFetchClient = (initBaseConfig = {}) => {
887
892
  if (shouldThrowOnError) throw error;
888
893
  return generalErrorResult;
889
894
  };
890
- if (isValidationErrorInstance(error)) return await executeHooksInCatchBlock([
891
- options.onValidationError?.(errorContext),
892
- options.onRequestError?.(errorContext),
893
- options.onError?.(errorContext)
894
- ], hookInfo) ?? await handleRetryOrGetErrorResult();
895
+ if (isValidationErrorInstance(error)) return await executeHooksInCatchBlock([options.onValidationError?.(errorContext), options.onError?.(errorContext)], hookInfo) ?? await handleRetryOrGetErrorResult();
895
896
  if (isHTTPErrorInstance(error)) return await executeHooksInCatchBlock([
896
897
  options.onResponseError?.(errorContext),
897
898
  options.onError?.(errorContext),