@@ -130,13 +130,14 @@ export async function ecfr({ path, params = {} }) {
130
130
const errorText = await response . text ( ) ;
131
131
throw new Error ( `eCFR API error (${ response . status } ): ${ errorText } ` ) ;
132
132
}
133
-
134
- // For . json paths, parse as JSON; for .xml paths, return as text
135
- if ( path . endsWith ( '.json' ) ) {
136
- return response . json ( ) ;
137
- } else {
138
- return response . text ( ) ;
133
+
134
+ let results = path . endsWith ( '. json' ) ? await response . json ( ) : await response . text ( ) ;
135
+ const stringifiedResults = JSON . stringify ( results , null , 2 ) ;
136
+ const limit = 10_000 ;
137
+ if ( stringifiedResults . length > limit ) {
138
+ results = stringifiedResults . slice ( 0 , limit ) + "\n... (truncated)" ;
139
139
}
140
+ return results ;
140
141
} catch ( error ) {
141
142
console . error ( "eCFR API error:" , error ) ;
142
143
throw error ;
@@ -170,13 +171,14 @@ export async function federalRegister({ path, params = {} }) {
170
171
const errorText = await response . text ( ) ;
171
172
throw new Error ( `Federal Register API error (${ response . status } ): ${ errorText } ` ) ;
172
173
}
173
-
174
- // For . json paths, parse as JSON; for .csv paths, return as text
175
- if ( path . endsWith ( '.json' ) ) {
176
- return response . json ( ) ;
177
- } else {
178
- return response . text ( ) ;
174
+
175
+ let results = path . endsWith ( '. json' ) ? await response . json ( ) : await response . text ( ) ;
176
+ const stringifiedResults = JSON . stringify ( results , null , 2 ) ;
177
+ const limit = 10_000 ;
178
+ if ( stringifiedResults . length > limit ) {
179
+ results = stringifiedResults . slice ( 0 , limit ) + "\n... (truncated)" ;
179
180
}
181
+ return results ;
180
182
} catch ( error ) {
181
183
console . error ( "Federal Register API error:" , error ) ;
182
184
throw error ;
0 commit comments