Skip to content

Commit c1b0899

Browse files
authored
fix: better log parsing (#21)
1 parent 8f0ad51 commit c1b0899

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

worker/src/Consumer/getConsumer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export async function create() {
3030
try {
3131
await boss.start();
3232
} catch (e: any) {
33+
if (e.errors) {
34+
throw new ApplicationError("CONSUMER", "START_FAILED", `Failed to start listener ${e.errors}. Exiting`);
35+
}
3336
throw new ApplicationError("CONSUMER", "START_FAILED", `Failed to start listener ${e.message}. Exiting`);
3437
}
3538

worker/src/queues/submission/workers/submit.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import config from "config";
77
const queue = "submission";
88
const worker = "submit";
99

10-
const ERROR_CODE = "SUBMIT_ERROR";
11-
1210
const logger = pino().child({
1311
queue,
1412
worker,
@@ -43,10 +41,8 @@ export async function submitHandler(job: Job<SubmitJob>) {
4341
}
4442
return;
4543
} catch (e: any) {
46-
logger.error({ jobId, err: e, errorCode: ERROR_CODE }, `post to ${url} job: ${id} failed with ${e.cause ?? e.message}`);
47-
4844
if (e.response) {
49-
logger.error({ jobId, err: e.response.error });
45+
logger.error({ jobId, errorCode: "SUBMIT_RESPONSE_ERROR", err: e.response.data }, `${jobId} POST to ${url} failed`);
5046
const { message, name, code, response } = e;
5147
const { status, data } = response;
5248
throw {
@@ -59,13 +55,17 @@ export async function submitHandler(job: Job<SubmitJob>) {
5955
}
6056

6157
if (e.request) {
62-
logger.error(jobId, `post to ${url} request could not be sent, see database for error`);
58+
logger.error({ jobId, errorCode: "SUBMIT_REQUEST_ERROR", e }, `post to ${url} request could not be sent`);
59+
throw e;
6360
}
6461

6562
// @ts-ignore
6663
if (e.cause instanceof AggregateError) {
6764
throw { errors: e.cause.errors };
6865
}
66+
67+
logger.error({ jobId, err: e, errorCode: "SUBMIT_ERROR_UNKNOWN" }, `post to ${url} job: ${id} failed with ${e.cause ?? e.message ?? e}`);
68+
6969
throw e;
7070
}
7171
}

0 commit comments

Comments
 (0)