@izak0s/spacebring-api 1.3.0 → 1.3.1
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 +16 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -486,7 +486,9 @@ var SpacebringError = class extends Error {
|
|
|
486
486
|
url;
|
|
487
487
|
constructor(status, body, request) {
|
|
488
488
|
const parsed = isErrorBody(body) ? body : void 0;
|
|
489
|
-
|
|
489
|
+
let base = parsed?.message ?? `Spacebring API request failed with status ${status}`;
|
|
490
|
+
const issues = parsed ? issueSummary(parsed) : void 0;
|
|
491
|
+
if (issues) base += ` \u2014 ${issues}`;
|
|
490
492
|
super(request?.operation ? `${base} (${request.operation})` : base);
|
|
491
493
|
this.name = "SpacebringError";
|
|
492
494
|
this.status = status;
|
|
@@ -498,6 +500,19 @@ var SpacebringError = class extends Error {
|
|
|
498
500
|
function isErrorBody(body) {
|
|
499
501
|
return typeof body === "object" && body !== null;
|
|
500
502
|
}
|
|
503
|
+
function issueSummary(body) {
|
|
504
|
+
const issues = body.issues;
|
|
505
|
+
if (!Array.isArray(issues) || issues.length === 0) return void 0;
|
|
506
|
+
const parts = issues.slice(0, 3).map((issue) => {
|
|
507
|
+
if (typeof issue !== "object" || issue === null) return String(issue);
|
|
508
|
+
const { path, message } = issue;
|
|
509
|
+
const where = Array.isArray(path) && path.length > 0 ? path.join(".") : void 0;
|
|
510
|
+
const what = typeof message === "string" ? message : JSON.stringify(issue);
|
|
511
|
+
return where ? `${where}: ${what}` : what;
|
|
512
|
+
});
|
|
513
|
+
const more = issues.length > 3 ? `; +${issues.length - 3} more` : "";
|
|
514
|
+
return parts.join("; ") + more;
|
|
515
|
+
}
|
|
501
516
|
|
|
502
517
|
// src/core.ts
|
|
503
518
|
function unwrap(result, operation) {
|