@@ -57,7 +57,7 @@ export const customFetch = async (input: RequestInfo, init?: RequestInit, logger
57
57
58
58
const response = await persistentFetch ( input , requestOptionsWithRetry )
59
59
if ( response && ! response . ok ) {
60
- throw throwHttpError ( response )
60
+ throwHttpError ( response )
61
61
}
62
62
return await response . json ( )
63
63
} ;
@@ -102,10 +102,11 @@ export class OnaApiService {
102
102
return Result . ok < Form > ( res ) ;
103
103
} )
104
104
. catch ( ( err : Error ) => {
105
+ const failResult = Result . fail < Form > ( err , NETWORK_ERROR )
105
106
this . logger ?.(
106
- createErrorLog ( `Operation to fetch form: ${ formId } , failed with err: ${ err } ` )
107
+ createErrorLog ( `Operation to fetch form: ${ formId } , failed with err: ${ failResult . error } ` )
107
108
) ;
108
- return Result . fail < Form > ( err , NETWORK_ERROR ) ;
109
+ return failResult
109
110
} ) ;
110
111
}
111
112
@@ -183,16 +184,18 @@ export class OnaApiService {
183
184
return Result . ok ( res ) ;
184
185
} )
185
186
. catch ( ( err : Error ) => {
186
- this . logger ?.(
187
- createErrorLog (
188
- `Unable to fetch submissions for form id: ${ formId } page: ${ paginatedSubmissionsUrl } with err : ${ err . message } `
189
- )
190
- ) ;
187
+
191
188
let recsAffected = pageSize ;
192
189
if ( ( totalSubmissions - ( page * pageSize ) ) < pageSize ) [
193
190
recsAffected = totalSubmissions - ( page * pageSize )
194
191
]
195
- return Result . fail < FormSubmissionT [ ] > ( err , { code : NETWORK_ERROR , recsAffected, } ) ;
192
+ const failResult = Result . fail < FormSubmissionT [ ] > ( err , { code : NETWORK_ERROR , recsAffected, } ) ;
193
+ this . logger ?.(
194
+ createErrorLog (
195
+ `Unable to fetch submissions for form id: ${ formId } page: ${ paginatedSubmissionsUrl } with err : ${ failResult . error } `
196
+ )
197
+ ) ;
198
+ return failResult
196
199
} ) ;
197
200
} while ( page * pageSize <= totalSubmissions ) ;
198
201
}
@@ -239,12 +242,13 @@ export class OnaApiService {
239
242
return Result . ok < Record < string , string > > ( res ) ;
240
243
} )
241
244
. catch ( ( err ) => {
245
+ const failResult = Result . fail ( err , NETWORK_ERROR )
242
246
this . logger ?.(
243
247
createErrorLog (
244
- `Failed to edit sumbission with _id: ${ submissionPayload . _id } for form with id: ${ formId } with err: ${ err . message } `
248
+ `Failed to edit sumbission with _id: ${ submissionPayload . _id } for form with id: ${ formId } with err: ${ failResult . error } `
245
249
)
246
250
) ;
247
- return Result . fail ( err , NETWORK_ERROR ) ;
251
+ return failResult ;
248
252
} ) ;
249
253
}
250
254
}
@@ -283,5 +287,5 @@ function throwHttpError(response: Response) {
283
287
? errorDetails . join ( ' | ' )
284
288
: "An unknown network error occurred." ;
285
289
286
- return errorMessage
290
+ throw new Error ( errorMessage )
287
291
}
0 commit comments