@wix/vibe-forms-app-plugin 0.25.0 → 0.26.0

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/index.cjs CHANGED
@@ -144742,6 +144742,38 @@ function findConsistentHeader(response) {
144742
144742
  }
144743
144743
 
144744
144744
  // src/wix-apis.ts
144745
+ var safeParseJSON = (text) => {
144746
+ try {
144747
+ return JSON.parse(text);
144748
+ } catch {
144749
+ return text;
144750
+ }
144751
+ };
144752
+ var handleWixAPIResponse = async (response, logger, context) => {
144753
+ const responseText = await response.text();
144754
+ const responseData = safeParseJSON(responseText);
144755
+ if (!response.ok) {
144756
+ const requestId = response.headers.get("x-wix-request-id");
144757
+ const errorDetails = typeof responseData === "object" ? JSON.stringify(responseData) : responseData;
144758
+ const errorMessage = [
144759
+ `Failed to call Wix API: ${response.status} ${response.statusText}.`,
144760
+ requestId ? `request id: ${requestId}` : "",
144761
+ response.status === 404 && errorDetails.includes("<html") ? "Not found" : errorDetails
144762
+ ].filter((str) => !!str).join("\n");
144763
+ logger.error(new Error(`[wix-apis] ${errorMessage}`), {
144764
+ url: context?.url,
144765
+ method: context?.method,
144766
+ body: context?.body,
144767
+ requestId,
144768
+ status: response.status,
144769
+ statusText: response.statusText,
144770
+ responseData,
144771
+ responseText
144772
+ });
144773
+ throw new Error(errorMessage);
144774
+ }
144775
+ return responseData;
144776
+ };
144745
144777
  var callWixAPI = async ({
144746
144778
  url,
144747
144779
  method,
@@ -144767,38 +144799,19 @@ var callWixAPI = async ({
144767
144799
  },
144768
144800
  ...method === "GET" ? {} : { body: JSON.stringify(body) }
144769
144801
  });
144770
- if (!response.ok) {
144771
- const responseText = await response.text();
144772
- logger.error(new Error("[wix-apis] Error calling Wix API"), {
144773
- responseText,
144774
- url,
144775
- method,
144776
- body,
144777
- requestId: response.headers.get("x-wix-request-id")
144778
- });
144779
- logger.debug("[wix-apis] Wix API response error", {
144780
- responseText,
144802
+ return await handleWixAPIResponse(response, logger, { url, method, body });
144803
+ } catch (error) {
144804
+ const errorMessage = error instanceof Error ? error.message : String(error);
144805
+ logger.error(
144806
+ new Error(`[wix-apis] Error calling Wix API: ${errorMessage}`),
144807
+ {
144808
+ error,
144781
144809
  url,
144782
144810
  method,
144783
144811
  body,
144784
- requestId: response.headers.get("x-wix-request-id")
144785
- });
144786
- return null;
144787
- }
144788
- return await response.json();
144789
- } catch (error) {
144790
- logger.error(new Error("[wix-apis] Error calling Wix API"), {
144791
- error,
144792
- url,
144793
- method,
144794
- body,
144795
- requestId: error instanceof Error && "requestId" in error ? error.requestId : void 0
144796
- });
144797
- logger.debug("[wix-apis] Wix API response error", {
144798
- url,
144799
- method,
144800
- body
144801
- });
144812
+ requestId: error instanceof Error && "requestId" in error ? error.requestId : void 0
144813
+ }
144814
+ );
144802
144815
  return null;
144803
144816
  }
144804
144817
  };