Skip to content

Commit 22c0ff9

Browse files
authored
Update message logging to include more details (#15)
1 parent e95461e commit 22c0ff9

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

packages/core/src/evaluator/tests/pipelinesController.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ it('error when fetching the registration form', async () => {
175175
[
176176
{
177177
"level": "error",
178-
"message": "Operation to fetch form: 3623, failed with err: Request failed for | URL: https://test-api.ona.io/api/v1/forms/3623 | Status: 400",
178+
"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",
179179
},
180180
],
181181
]);

packages/core/src/services/onaApi/services.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const customFetch = async (input: RequestInfo, init?: RequestInit, logger
5757

5858
const response = await persistentFetch(input, requestOptionsWithRetry)
5959
if (response && !response.ok) {
60-
throw throwHttpError(response)
60+
throwHttpError(response)
6161
}
6262
return await response.json()
6363
};
@@ -102,10 +102,11 @@ export class OnaApiService {
102102
return Result.ok<Form>(res);
103103
})
104104
.catch((err: Error) => {
105+
const failResult = Result.fail<Form>(err, NETWORK_ERROR)
105106
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}`)
107108
);
108-
return Result.fail<Form>(err, NETWORK_ERROR);
109+
return failResult
109110
});
110111
}
111112

@@ -183,16 +184,18 @@ export class OnaApiService {
183184
return Result.ok(res);
184185
})
185186
.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+
191188
let recsAffected = pageSize;
192189
if ((totalSubmissions - (page * pageSize)) < pageSize) [
193190
recsAffected = totalSubmissions - (page * pageSize)
194191
]
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
196199
});
197200
} while (page * pageSize <= totalSubmissions);
198201
}
@@ -239,12 +242,13 @@ export class OnaApiService {
239242
return Result.ok<Record<string, string>>(res);
240243
})
241244
.catch((err) => {
245+
const failResult = Result.fail(err, NETWORK_ERROR)
242246
this.logger?.(
243247
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}`
245249
)
246250
);
247-
return Result.fail(err, NETWORK_ERROR);
251+
return failResult;
248252
});
249253
}
250254
}
@@ -283,5 +287,5 @@ function throwHttpError(response: Response) {
283287
? errorDetails.join(' | ')
284288
: "An unknown network error occurred.";
285289

286-
return errorMessage
290+
throw new Error(errorMessage)
287291
}

0 commit comments

Comments
 (0)