@@ -23,13 +23,32 @@ export async function improveResume(
23
23
resumeId : string ,
24
24
jobId : string
25
25
) : Promise < ImprovedResult > {
26
- const res = await fetch ( `${ API_URL } /api/v1/resumes/improve` , {
27
- method : 'POST' ,
28
- headers : { 'Content-Type' : 'application/json' } ,
29
- body : JSON . stringify ( { resume_id : resumeId , job_id : jobId } ) ,
30
- } ) ;
31
- if ( ! res . ok ) throw new Error ( `Improve failed with status ${ res . status } ` ) ;
32
- const data = await res . json ( ) ;
26
+ let response : Response ;
27
+ try {
28
+ response = await fetch ( `${ API_URL } /api/v1/resumes/improve` , {
29
+ method : 'POST' ,
30
+ headers : { 'Content-Type' : 'application/json' } ,
31
+ body : JSON . stringify ( { resume_id : resumeId , job_id : jobId } ) ,
32
+ } ) ;
33
+ } catch ( networkError ) {
34
+ console . error ( 'Network error during improveResume:' , networkError ) ;
35
+ throw networkError ;
36
+ }
37
+
38
+ const text = await response . text ( ) ;
39
+ if ( ! response . ok ) {
40
+ console . error ( 'Improve failed response body:' , text ) ;
41
+ throw new Error ( `Improve failed with status ${ response . status } : ${ text } ` ) ;
42
+ }
43
+
44
+ let data : ImprovedResult ;
45
+ try {
46
+ data = JSON . parse ( text ) as ImprovedResult ;
47
+ } catch ( parseError ) {
48
+ console . error ( 'Failed to parse improveResume response:' , parseError , 'Raw response:' , text ) ;
49
+ throw parseError ;
50
+ }
51
+
33
52
console . log ( 'Resume improvement response:' , data ) ;
34
- return data as ImprovedResult ;
53
+ return data ;
35
54
}
0 commit comments