File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
packages/cli/src/cli/localizer Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -275,21 +275,29 @@ function createAiSdkLocalizer(params: {
275275 ] ,
276276 } ) ;
277277
278- const result = parseModelResponse ( response . text ) ;
278+ let result : any ;
279+ try {
280+ result = parseModelResponse ( response . text ) ;
281+ } catch ( e2 ) {
282+ console . error (
283+ `Failed to parse response from Lingo.dev. Response: ${ response . text } ` ,
284+ ) ;
285+ throw new Error ( `Failed to parse response from Lingo.dev: ${ e2 } ` ) ;
286+ }
279287 let finalResult : Record < string , any > = { } ;
280288
281289 // Handle both object and string responses
282- if ( typeof result . data === "object" && result . data !== null ) {
290+ if ( typeof result ? .data === "object" && result . data !== null ) {
283291 finalResult = result . data ;
284- } else if ( result . data ) {
292+ } else if ( result ? .data ) {
285293 // Handle string responses - extract and repair JSON
286294 const index = result . data . indexOf ( "{" ) ;
287295 const lastIndex = result . data . lastIndexOf ( "}" ) ;
288296 if ( index !== - 1 && lastIndex !== - 1 ) {
289297 const trimmed = result . data . slice ( index , lastIndex + 1 ) ;
290298 const repaired = jsonrepair ( trimmed ) ;
291299 const parsed = JSON . parse ( repaired ) ;
292- finalResult = parsed . data || { } ;
300+ finalResult = parsed . data || parsed || { } ;
293301 }
294302 }
295303
You can’t perform that action at this time.
0 commit comments