@continuedev/fetch 1.0.15 → 1.0.16

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.
@@ -2,6 +2,7 @@ import { globalAgent } from "https";
2
2
  import * as fs from "node:fs";
3
3
  import * as os from "node:os";
4
4
  import * as path from "node:path";
5
+ import { afterEach, beforeEach, expect, test } from "vitest";
5
6
  import { getAgentOptions } from "./getAgentOptions.js";
6
7
  // Store original env
7
8
  const originalEnv = process.env;
package/dist/stream.js CHANGED
@@ -67,7 +67,13 @@ export function parseDataLine(line) {
67
67
  try {
68
68
  const data = JSON.parse(json);
69
69
  if (data.error) {
70
- throw new Error(`Error streaming response: ${data.error}`);
70
+ if (data.error &&
71
+ typeof data.error === "object" &&
72
+ "message" in data.error) {
73
+ console.error("Error in streamed response:", data.error);
74
+ throw new Error(`Error streaming response: ${data.error.message}`);
75
+ }
76
+ throw new Error(`Error streaming response: ${JSON.stringify(data.error)}`);
71
77
  }
72
78
  return data;
73
79
  }
@@ -69,7 +69,7 @@ describe("parseDataLine", () => {
69
69
  });
70
70
  test("parseDataLine should throw error when data contains error field", () => {
71
71
  const line = 'data: {"error":"something went wrong"}';
72
- expect(() => parseDataLine(line)).toThrow("Error streaming response: something went wrong");
72
+ expect(() => parseDataLine(line)).toThrow('Error streaming response: "something went wrong"');
73
73
  });
74
74
  test("parseDataLine should handle empty objects", () => {
75
75
  const line = "data: {}";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@continuedev/fetch",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -86,7 +86,7 @@ describe("parseDataLine", () => {
86
86
  test("parseDataLine should throw error when data contains error field", () => {
87
87
  const line = 'data: {"error":"something went wrong"}';
88
88
  expect(() => parseDataLine(line)).toThrow(
89
- "Error streaming response: something went wrong",
89
+ 'Error streaming response: "something went wrong"',
90
90
  );
91
91
  });
92
92
 
package/src/stream.ts CHANGED
@@ -81,7 +81,17 @@ export function parseDataLine(line: string): any {
81
81
  try {
82
82
  const data = JSON.parse(json);
83
83
  if (data.error) {
84
- throw new Error(`Error streaming response: ${data.error}`);
84
+ if (
85
+ data.error &&
86
+ typeof data.error === "object" &&
87
+ "message" in data.error
88
+ ) {
89
+ console.error("Error in streamed response:", data.error);
90
+ throw new Error(`Error streaming response: ${data.error.message}`);
91
+ }
92
+ throw new Error(
93
+ `Error streaming response: ${JSON.stringify(data.error)}`,
94
+ );
85
95
  }
86
96
 
87
97
  return data;
@@ -1 +0,0 @@
1
- {"version":"3.2.0","results":[[":node-fetch-bug.test.ts",{"duration":10.538165999999933,"failed":true}],[":boundary-assumption.test.ts",{"duration":392.1355840000324,"failed":false}],[":chunk-transformer.test.ts",{"duration":0,"failed":true}],[":fetch.test.ts",{"duration":115.30825000000186,"failed":false}],[":getAgentOptions.test.ts",{"duration":6.5474579999936395,"failed":false}],[":stream.test.ts",{"duration":68.50500000000466,"failed":false}],[":premature-close.test.ts",{"duration":5329.249708,"failed":true}],[":util.test.ts",{"duration":3.016583999999966,"failed":false}]]}
@@ -1 +0,0 @@
1
- {"version":"3.2.1","results":[[":node-fetch-patch.test.ts",{"duration":125.8410000000149,"failed":true}],[":remove/node-fetch-patch.test.ts",{"duration":214.92558300006203,"failed":true}],[":patch-test.test.js",{"duration":1.4479579999999999,"failed":false}],[":premature-close.test.ts",{"duration":5396.810541999992,"failed":true}],[":util.test.ts",{"duration":4.095832999795675,"failed":false}]]}