@rustrak/client 0.14.0 → 0.14.2

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.js CHANGED
@@ -713,6 +713,11 @@ function warnUnknownFieldErrorCode(code, field) {
713
713
  `[@rustrak/client] Dropped a field error with an unrecognised code "${code}" (field "${field}"). This client build does not know that code, so the affected inputs degrade to a form-level error. The server is most likely newer than @rustrak/client; upgrade the client to match the server version.`
714
714
  );
715
715
  }
716
+ function readIncidentId(error) {
717
+ const body = error.data;
718
+ const raw = body && typeof body === "object" ? body.error?.incident_id : void 0;
719
+ return typeof raw === "string" && raw.length > 0 ? raw : void 0;
720
+ }
716
721
  function readFieldErrors(error) {
717
722
  const body = error.data;
718
723
  const raw = body && typeof body === "object" ? body.error?.fields : void 0;
@@ -758,7 +763,13 @@ function transformHttpError(error) {
758
763
  const { response } = error;
759
764
  const status = response.status;
760
765
  if (status >= 500) {
761
- return { kind: "server_error", status, message: SERVER_ERROR_MESSAGE };
766
+ const base = {
767
+ kind: "server_error",
768
+ status,
769
+ message: SERVER_ERROR_MESSAGE
770
+ };
771
+ const incidentId = readIncidentId(error);
772
+ return incidentId === void 0 ? base : { ...base, incidentId };
762
773
  }
763
774
  const message = readErrorMessage(error, status);
764
775
  const fields = readFieldErrors(error);