@szymonpiatek/nextwordpress 0.0.14 → 0.0.15

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.
@@ -2135,7 +2135,25 @@ function createWPULikeClient(config) {
2135
2135
  return createWPULikeQueries(fetcher);
2136
2136
  }
2137
2137
 
2138
+ // src/integrations/restApi/contactForm7/types.ts
2139
+ var CF7Error = class extends Error {
2140
+ constructor(code, status, endpoint, message) {
2141
+ super(message);
2142
+ __publicField(this, "code", code);
2143
+ __publicField(this, "status", status);
2144
+ __publicField(this, "endpoint", endpoint);
2145
+ this.name = "CF7Error";
2146
+ }
2147
+ };
2148
+
2138
2149
  // src/integrations/restApi/contactForm7/queries.ts
2150
+ var statusToCode = {
2151
+ mail_sent: ErrorCode.CF7_MAIL_SENT,
2152
+ mail_failed: ErrorCode.CF7_MAIL_FAILED,
2153
+ validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
2154
+ spam: ErrorCode.CF7_SPAM,
2155
+ aborted: ErrorCode.CF7_ABORTED
2156
+ };
2139
2157
  function createCF7Queries(config) {
2140
2158
  async function submitForm(formId, data) {
2141
2159
  const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
@@ -2144,7 +2162,17 @@ function createCF7Queries(config) {
2144
2162
  body.append(key, value);
2145
2163
  }
2146
2164
  const res = await fetch(url, { method: "POST", body, cache: "no-store" });
2147
- return res.json();
2165
+ if (!res.ok) {
2166
+ throw new CF7Error(
2167
+ ErrorCode.CF7_MAIL_FAILED,
2168
+ res.status,
2169
+ url,
2170
+ resolveMessage(ErrorCode.CF7_MAIL_FAILED, config.errorMessages)
2171
+ );
2172
+ }
2173
+ const result = await res.json();
2174
+ const code = statusToCode[result.status];
2175
+ return { ...result, message: resolveMessage(code, config.errorMessages) };
2148
2176
  }
2149
2177
  return { submitForm };
2150
2178
  }
@@ -4330,6 +4358,7 @@ async function validateJwtToken(config, token) {
4330
4358
  }
4331
4359
 
4332
4360
  exports.AuthenticationError = AuthenticationError;
4361
+ exports.CF7Error = CF7Error;
4333
4362
  exports.ErrorCode = ErrorCode;
4334
4363
  exports.WPGraphQLError = WPGraphQLError;
4335
4364
  exports.WooCommerceError = WooCommerceError;