better-call 1.0.7 → 1.0.9

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
  });
@@ -4866,6 +4875,18 @@ var createRouter = (endpoints, config) => {
4866
4875
  if (!route?.data) {
4867
4876
  return new Response(null, { status: 404, statusText: "Not Found" });
4868
4877
  }
4878
+ const query = {};
4879
+ url.searchParams.forEach((value, key) => {
4880
+ if (key in query) {
4881
+ if (Array.isArray(query[key])) {
4882
+ query[key].push(value);
4883
+ } else {
4884
+ query[key] = [query[key], value];
4885
+ }
4886
+ } else {
4887
+ query[key] = value;
4888
+ }
4889
+ });
4869
4890
  const handler = route.data;
4870
4891
  const context = {
4871
4892
  path,
@@ -4874,7 +4895,7 @@ var createRouter = (endpoints, config) => {
4874
4895
  params: route.params ? JSON.parse(JSON.stringify(route.params)) : {},
4875
4896
  request,
4876
4897
  body: await getBody(handler.options.cloneRequest ? request.clone() : request),
4877
- query: Object.fromEntries(url.searchParams),
4898
+ query,
4878
4899
  _flag: "router",
4879
4900
  asResponse: true,
4880
4901
  context: config?.routerContext