heyreach-cli 0.1.2 → 0.1.3

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/mcp.js CHANGED
@@ -39,7 +39,9 @@ var init_config = __esm({
39
39
  // src/core/errors.ts
40
40
  function classifyHttpError(status, body) {
41
41
  const parsed = safeParse(body);
42
- const message = parsed?.message || parsed?.error || body || `HTTP ${status} error`;
42
+ const rawVal = parsed?.message || parsed?.error || body || `HTTP ${status} error`;
43
+ const raw = typeof rawVal === "string" ? rawVal : JSON.stringify(rawVal);
44
+ const message = extractMessage(raw);
43
45
  if (status === 401 || status === 403) return new AuthError(message);
44
46
  if (status === 404) return new NotFoundError(message);
45
47
  if (status === 422) return new ValidationError(message);
@@ -47,6 +49,18 @@ function classifyHttpError(status, body) {
47
49
  if (status >= 500) return new ServerError(message);
48
50
  return new HeyReachError(message, "HTTP_ERROR", status);
49
51
  }
52
+ function extractMessage(raw) {
53
+ const nested = safeParse(raw);
54
+ if (nested?.errors && typeof nested.errors === "object") {
55
+ const parts = [];
56
+ for (const [field, msgs] of Object.entries(nested.errors)) {
57
+ const msgList = Array.isArray(msgs) ? msgs.join("; ") : String(msgs);
58
+ parts.push(`${field}: ${msgList}`);
59
+ }
60
+ if (parts.length > 0) return parts.join(". ");
61
+ }
62
+ return raw;
63
+ }
50
64
  function safeParse(text) {
51
65
  try {
52
66
  return JSON.parse(text);