@ai-matrx/records 0.46.0 → 0.47.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.
@@ -2439,19 +2439,34 @@ function parseDetail(details) {
2439
2439
  return details;
2440
2440
  }
2441
2441
  }
2442
+ function isNotASqlstate(code) {
2443
+ if (!code) return true;
2444
+ return /^[0-9]{3}$/.test(code);
2445
+ }
2442
2446
  function mapPgError(error, where) {
2443
- const sqlstate = error.code ?? void 0;
2444
- const code = (sqlstate ? BY_SQLSTATE[sqlstate] : void 0) ?? "internal";
2447
+ const raw = error.code ?? void 0;
2448
+ const sqlstate = raw && raw !== "" ? raw : void 0;
2445
2449
  const mapped = {
2446
- code,
2450
+ code: "internal",
2447
2451
  message: error.message,
2448
2452
  ...error.hint ? { hint: error.hint } : {},
2449
2453
  ...sqlstate ? { sqlstate } : {}
2450
2454
  };
2455
+ if (isNotASqlstate(sqlstate)) {
2456
+ mapped.code = "unreachable";
2457
+ } else {
2458
+ mapped.code = BY_SQLSTATE[sqlstate] ?? "internal";
2459
+ }
2451
2460
  const detail = parseDetail(error.details);
2452
2461
  if (detail !== void 0) mapped.detail = detail;
2453
- if (code === "internal") {
2454
- mapped.hint = (mapped.hint ? `${mapped.hint} ` : "") + `(@ai-matrx/records did not recognise SQLSTATE ${sqlstate ?? "(none)"} from ${where}; the message above is the store's own and is the thing to act on.)`;
2462
+ if (mapped.code === "internal") {
2463
+ mapped.unmapped = true;
2464
+ mapped.diagnostic = `@ai-matrx/records did not recognise SQLSTATE ${sqlstate ?? "(none)"} from ${where}; the store's own message is the thing to act on.`;
2465
+ } else if (mapped.code === "unreachable") {
2466
+ mapped.unmapped = true;
2467
+ mapped.diagnostic = `@ai-matrx/records never reached the store from ${where}: ${raw ? `the transport answered ${raw}` : "no response"} \u2014 ${error.message}`;
2468
+ mapped.message = "We could not reach your data.";
2469
+ delete mapped.hint;
2455
2470
  }
2456
2471
  return mapped;
2457
2472
  }