@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.cjs CHANGED
@@ -719,6 +719,11 @@ function warnUnknownFieldErrorCode(code, field) {
719
719
  `[@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.`
720
720
  );
721
721
  }
722
+ function readIncidentId(error) {
723
+ const body = error.data;
724
+ const raw = body && typeof body === "object" ? body.error?.incident_id : void 0;
725
+ return typeof raw === "string" && raw.length > 0 ? raw : void 0;
726
+ }
722
727
  function readFieldErrors(error) {
723
728
  const body = error.data;
724
729
  const raw = body && typeof body === "object" ? body.error?.fields : void 0;
@@ -764,7 +769,13 @@ function transformHttpError(error) {
764
769
  const { response } = error;
765
770
  const status = response.status;
766
771
  if (status >= 500) {
767
- return { kind: "server_error", status, message: SERVER_ERROR_MESSAGE };
772
+ const base = {
773
+ kind: "server_error",
774
+ status,
775
+ message: SERVER_ERROR_MESSAGE
776
+ };
777
+ const incidentId = readIncidentId(error);
778
+ return incidentId === void 0 ? base : { ...base, incidentId };
768
779
  }
769
780
  const message = readErrorMessage(error, status);
770
781
  const fields = readFieldErrors(error);