diff --git a/packages/core/src/evaluator/tests/pipelinesController.test.ts b/packages/core/src/evaluator/tests/pipelinesController.test.ts index be2b00e..2b5b14f 100644 --- a/packages/core/src/evaluator/tests/pipelinesController.test.ts +++ b/packages/core/src/evaluator/tests/pipelinesController.test.ts @@ -175,7 +175,7 @@ it('error when fetching the registration form', async () => { [ { "level": "error", - "message": "Operation to fetch form: 3623, failed with err: Request failed for | URL: https://test-api.ona.io/api/v1/forms/3623 | Status: 400", + "message": "Operation to fetch form: 3623, failed with err: Error Name: Error | Message: Request failed for | URL: https://test-api.ona.io/api/v1/forms/3623 | Status: 400", }, ], ]); diff --git a/packages/core/src/services/onaApi/services.ts b/packages/core/src/services/onaApi/services.ts index 870f00d..6f89809 100644 --- a/packages/core/src/services/onaApi/services.ts +++ b/packages/core/src/services/onaApi/services.ts @@ -57,7 +57,7 @@ export const customFetch = async (input: RequestInfo, init?: RequestInit, logger const response = await persistentFetch(input, requestOptionsWithRetry) if (response && !response.ok) { - throw throwHttpError(response) + throwHttpError(response) } return await response.json() }; @@ -102,10 +102,11 @@ export class OnaApiService { return Result.ok
(res); }) .catch((err: Error) => { + const failResult = Result.fail(err, NETWORK_ERROR) this.logger?.( - createErrorLog(`Operation to fetch form: ${formId}, failed with err: ${err}`) + createErrorLog(`Operation to fetch form: ${formId}, failed with err: ${failResult.error}`) ); - return Result.fail(err, NETWORK_ERROR); + return failResult }); } @@ -183,16 +184,18 @@ export class OnaApiService { return Result.ok(res); }) .catch((err: Error) => { - this.logger?.( - createErrorLog( - `Unable to fetch submissions for form id: ${formId} page: ${paginatedSubmissionsUrl} with err : ${err.message}` - ) - ); + let recsAffected = pageSize; if ((totalSubmissions - (page * pageSize)) < pageSize) [ recsAffected = totalSubmissions - (page * pageSize) ] - return Result.fail(err, { code: NETWORK_ERROR, recsAffected, }); + const failResult = Result.fail(err, { code: NETWORK_ERROR, recsAffected, }); + this.logger?.( + createErrorLog( + `Unable to fetch submissions for form id: ${formId} page: ${paginatedSubmissionsUrl} with err : ${failResult.error}` + ) + ); + return failResult }); } while (page * pageSize <= totalSubmissions); } @@ -239,12 +242,13 @@ export class OnaApiService { return Result.ok>(res); }) .catch((err) => { + const failResult = Result.fail(err, NETWORK_ERROR) this.logger?.( createErrorLog( - `Failed to edit sumbission with _id: ${submissionPayload._id} for form with id: ${formId} with err: ${err.message}` + `Failed to edit sumbission with _id: ${submissionPayload._id} for form with id: ${formId} with err: ${failResult.error}` ) ); - return Result.fail(err, NETWORK_ERROR); + return failResult; }); } } @@ -283,5 +287,5 @@ function throwHttpError(response: Response) { ? errorDetails.join(' | ') : "An unknown network error occurred."; - return errorMessage + throw new Error(errorMessage) } \ No newline at end of file