@@ -4,7 +4,7 @@ import https from "node:https";
44import { dirname , join } from "node:path" ;
55import { fileURLToPath } from "node:url" ;
66
7- import axios , { AxiosInstance } from "axios" ;
7+ import axios , { AxiosInstance , AxiosResponse } from "axios" ;
88import { parse as csvParse } from "csv-parse/sync" ;
99import { z } from "zod" ;
1010
@@ -153,24 +153,28 @@ export class BaseIterableClient {
153153
154154 /**
155155 * Parse CSV response into an array of objects using csv-parse library
156+ * @throws IterableResponseValidationError if CSV parsing fails
156157 */
157- public parseCsv ( data : string ) : any [ ] {
158- if ( ! data ) {
158+ public parseCsv ( response : AxiosResponse < string > ) : Record < string , string > [ ] {
159+ if ( ! response . data ) {
159160 return [ ] ;
160161 }
161162
162163 try {
163- return csvParse ( data , {
164+ return csvParse ( response . data , {
164165 columns : true , // Use first line as headers
165166 skip_empty_lines : true ,
166167 trim : true ,
167168 } ) ;
168169 } catch ( error ) {
169- // Log error but don't throw - return empty array for graceful degradation
170- logger . warn ( "Failed to parse CSV data" , {
171- error : error instanceof Error ? error . message : String ( error ) ,
172- } ) ;
173- return [ ] ;
170+ // Throw validation error to maintain consistent error handling
171+ // This allows callers to handle parse failures appropriately
172+ throw new IterableResponseValidationError (
173+ 200 ,
174+ response . data ,
175+ `CSV parse error: ${ error instanceof Error ? error . message : String ( error ) } ` ,
176+ response . config ?. url
177+ ) ;
174178 }
175179 }
176180
0 commit comments