@jskit-ai/http-runtime 0.1.111 → 0.1.113
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/package.descriptor.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default Object.freeze({
|
|
2
2
|
"packageVersion": 1,
|
|
3
3
|
"packageId": "@jskit-ai/http-runtime",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.113",
|
|
5
5
|
"kind": "runtime",
|
|
6
6
|
"dependsOn": [],
|
|
7
7
|
"capabilities": {
|
|
@@ -67,7 +67,7 @@ export default Object.freeze({
|
|
|
67
67
|
"mutations": {
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"runtime": {
|
|
70
|
-
"@jskit-ai/kernel": "0.1.
|
|
70
|
+
"@jskit-ai/kernel": "0.1.114"
|
|
71
71
|
},
|
|
72
72
|
"dev": {}
|
|
73
73
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/http-runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.113",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"./shared/validators/operationValidation": "./src/shared/validators/operationValidation.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@jskit-ai/kernel": "0.1.
|
|
21
|
+
"@jskit-ai/kernel": "0.1.114",
|
|
22
22
|
"json-rest-schema": "1.x.x"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { isRecord, resolveFieldErrors } from "../support/fieldErrors.js";
|
|
2
2
|
import { createJsonApiClientErrorPayload } from "./jsonApiResourceTransport.js";
|
|
3
3
|
|
|
4
|
+
function standardErrorMessage(payload = {}) {
|
|
5
|
+
const nestedMessage = Array.isArray(payload.errors)
|
|
6
|
+
? payload.errors.find((entry) => isRecord(entry) && String(entry.message || "").trim())?.message
|
|
7
|
+
: "";
|
|
8
|
+
return String(payload.error || payload.message || nestedMessage || "").trim();
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
function createHttpError(response, data = {}) {
|
|
5
12
|
const payload = isRecord(data) ? data : {};
|
|
6
|
-
const
|
|
13
|
+
const message = standardErrorMessage(payload);
|
|
14
|
+
const jsonApiPayload = message ? null : createJsonApiClientErrorPayload(payload);
|
|
7
15
|
if (jsonApiPayload) {
|
|
8
16
|
return createHttpError(response, jsonApiPayload);
|
|
9
17
|
}
|
|
10
18
|
|
|
11
|
-
const error = new Error(
|
|
19
|
+
const error = new Error(message || `Request failed with status ${response.status}.`);
|
|
12
20
|
const normalizedFieldErrors = resolveFieldErrors(payload);
|
|
13
21
|
error.status = Number(response?.status || 0);
|
|
14
22
|
error.code = String(payload.code || "").trim() || null;
|
|
@@ -99,6 +99,56 @@ test("createHttpError normalizes code and fieldErrors", () => {
|
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
+
test("createHttpError preserves standard error envelopes that also contain an errors list", () => {
|
|
103
|
+
const error = createHttpError(
|
|
104
|
+
{
|
|
105
|
+
status: 409
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
code: "vibe64_repository_flip_active_sessions",
|
|
109
|
+
details: {
|
|
110
|
+
code: "vibe64_repository_flip_active_sessions"
|
|
111
|
+
},
|
|
112
|
+
error: "Finish or abandon active sessions before changing this project's repository mode.",
|
|
113
|
+
errors: [
|
|
114
|
+
{
|
|
115
|
+
code: "vibe64_repository_flip_active_sessions",
|
|
116
|
+
message: "Finish or abandon active sessions before changing this project's repository mode."
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
ok: false
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
assert.equal(error.status, 409);
|
|
124
|
+
assert.equal(error.code, "vibe64_repository_flip_active_sessions");
|
|
125
|
+
assert.equal(
|
|
126
|
+
error.message,
|
|
127
|
+
"Finish or abandon active sessions before changing this project's repository mode."
|
|
128
|
+
);
|
|
129
|
+
assert.deepEqual(error.details, {
|
|
130
|
+
code: "vibe64_repository_flip_active_sessions"
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("createHttpError reads errors-list messages when a standard envelope has no top-level message", () => {
|
|
135
|
+
const error = createHttpError(
|
|
136
|
+
{
|
|
137
|
+
status: 400
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
errors: [
|
|
141
|
+
{
|
|
142
|
+
code: "invalid_request",
|
|
143
|
+
message: "The request is invalid."
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
assert.equal(error.message, "The request is invalid.");
|
|
150
|
+
});
|
|
151
|
+
|
|
102
152
|
test("createHttpError decodes json:api error documents into the existing fieldErrors shape", () => {
|
|
103
153
|
const error = createHttpError(
|
|
104
154
|
{
|