better-call 1.0.7 → 1.0.8

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/dist/client.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BetterFetchOption, BetterFetchResponse } from '@better-fetch/fetch';
2
- import { j as Router, X as UnionToIntersection, b as Endpoint, U as HasRequiredKeys } from './router-mvPUuWw_.cjs';
2
+ import { j as Router, X as UnionToIntersection, b as Endpoint, U as HasRequiredKeys } from './router-Bn_wF2y_.cjs';
3
3
 
4
4
  type HasRequired<T extends {
5
5
  body?: any;
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BetterFetchOption, BetterFetchResponse } from '@better-fetch/fetch';
2
- import { j as Router, X as UnionToIntersection, b as Endpoint, U as HasRequiredKeys } from './router-mvPUuWw_.js';
2
+ import { j as Router, X as UnionToIntersection, b as Endpoint, U as HasRequiredKeys } from './router-Bn_wF2y_.js';
3
3
 
4
4
  type HasRequired<T extends {
5
5
  body?: any;
package/dist/index.cjs CHANGED
@@ -208,6 +208,9 @@ function toResponse(data, init) {
208
208
  let body = data;
209
209
  let headers = new Headers(init?.headers);
210
210
  if (!data) {
211
+ if (data === null) {
212
+ body = JSON.stringify(null);
213
+ }
211
214
  headers.set("content-type", "application/json");
212
215
  } else if (typeof data === "string") {
213
216
  body = data;
@@ -603,9 +606,15 @@ var createEndpoint2 = (path, options, handler) => {
603
606
  options,
604
607
  path
605
608
  });
606
- const response = await handler(internalContext).catch((e) => {
607
- if (isAPIError(e) && context.asResponse) {
608
- return e;
609
+ const response = await handler(internalContext).catch(async (e) => {
610
+ if (isAPIError(e)) {
611
+ const onAPIError = options.onAPIError;
612
+ if (onAPIError) {
613
+ await onAPIError(e);
614
+ }
615
+ if (context.asResponse) {
616
+ return e;
617
+ }
609
618
  }
610
619
  throw e;
611
620
  });