@nextclaw/ncp-http-agent-client 0.3.10 → 0.3.11
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.d.ts +1 -0
- package/dist/index.js +34 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -290,7 +290,7 @@ var NcpHttpAgentClientEndpoint = class {
|
|
|
290
290
|
}
|
|
291
291
|
async send(envelope) {
|
|
292
292
|
await this.ensureStarted();
|
|
293
|
-
await this.
|
|
293
|
+
await this.jsonRequest({
|
|
294
294
|
path: "/send",
|
|
295
295
|
method: "POST",
|
|
296
296
|
body: envelope
|
|
@@ -350,6 +350,39 @@ var NcpHttpAgentClientEndpoint = class {
|
|
|
350
350
|
resolveUrl(path) {
|
|
351
351
|
return new URL(`${this.basePath}${path}`, this.baseUrl);
|
|
352
352
|
}
|
|
353
|
+
async jsonRequest(options) {
|
|
354
|
+
const controller = new AbortController();
|
|
355
|
+
this.activeControllers.add(controller);
|
|
356
|
+
try {
|
|
357
|
+
const response = await this.fetchImpl(this.resolveUrl(options.path), {
|
|
358
|
+
method: options.method,
|
|
359
|
+
headers: {
|
|
360
|
+
...this.defaultHeaders,
|
|
361
|
+
"content-type": "application/json",
|
|
362
|
+
accept: "application/json"
|
|
363
|
+
},
|
|
364
|
+
body: options.body === void 0 ? void 0 : JSON.stringify(options.body),
|
|
365
|
+
signal: controller.signal
|
|
366
|
+
});
|
|
367
|
+
if (!response.ok) {
|
|
368
|
+
throw new Error(
|
|
369
|
+
`NCP request failed with HTTP ${response.status}: ${await safeReadText(response)}`
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
} catch (error) {
|
|
373
|
+
if (controller.signal.aborted) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (isNcpHttpAgentClientError(error)) {
|
|
377
|
+
throw error;
|
|
378
|
+
}
|
|
379
|
+
const ncpError = toNcpError(error);
|
|
380
|
+
this.publish({ type: NcpEventType.EndpointError, payload: ncpError });
|
|
381
|
+
throw ncpErrorToError(ncpError);
|
|
382
|
+
} finally {
|
|
383
|
+
this.activeControllers.delete(controller);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
353
386
|
async streamRequest(options) {
|
|
354
387
|
const controller = new AbortController();
|
|
355
388
|
this.activeControllers.add(controller);
|