@izak0s/spacebring-api 1.3.0 → 1.4.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.
package/dist/index.cjs CHANGED
@@ -513,7 +513,9 @@ var SpacebringError = class extends Error {
513
513
  url;
514
514
  constructor(status, body, request) {
515
515
  const parsed = isErrorBody(body) ? body : void 0;
516
- const base = parsed?.message ?? `Spacebring API request failed with status ${status}`;
516
+ let base = parsed?.message ?? `Spacebring API request failed with status ${status}`;
517
+ const issues = parsed ? issueSummary(parsed) : void 0;
518
+ if (issues) base += ` \u2014 ${issues}`;
517
519
  super(request?.operation ? `${base} (${request.operation})` : base);
518
520
  this.name = "SpacebringError";
519
521
  this.status = status;
@@ -525,6 +527,19 @@ var SpacebringError = class extends Error {
525
527
  function isErrorBody(body) {
526
528
  return typeof body === "object" && body !== null;
527
529
  }
530
+ function issueSummary(body) {
531
+ const issues = body.issues;
532
+ if (!Array.isArray(issues) || issues.length === 0) return void 0;
533
+ const parts = issues.slice(0, 3).map((issue) => {
534
+ if (typeof issue !== "object" || issue === null) return String(issue);
535
+ const { path, message } = issue;
536
+ const where = Array.isArray(path) && path.length > 0 ? path.join(".") : void 0;
537
+ const what = typeof message === "string" ? message : JSON.stringify(issue);
538
+ return where ? `${where}: ${what}` : what;
539
+ });
540
+ const more = issues.length > 3 ? `; +${issues.length - 3} more` : "";
541
+ return parts.join("; ") + more;
542
+ }
528
543
 
529
544
  // src/core.ts
530
545
  function unwrap(result, operation) {