Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 6acd570

Browse files
Prevent joi from polluting log with error messages about kafka message it should be ignoring. Also fix error where checking if record exists would throw errors
1 parent daaf4c3 commit 6acd570

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ const dataHandler = (messageSet, topic, partition) => Promise.each(messageSet, a
4242
return
4343
}
4444

45+
if (messageJSON.payload.resource !== 'upload') {
46+
logger.info(`The message payload resource ${messageJSON.payload.resource} is not "upload". Ignoring message.`)
47+
48+
return
49+
}
50+
4551
try {
4652
await ProcessorService.processCreate(messageJSON)
4753

src/common/helper.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,19 @@ async function getUbahnSingleRecord (path, params, isOptionRecord) {
105105

106106
logger.debug(`request GET ${path} by params: ${JSON.stringify(params)}`)
107107
try {
108-
const res = await axios.get(`${config.UBAHN_API_URL}${path}`, { headers: { Authorization: `Bearer ${token}` }, params })
108+
const res = await axios.get(`${config.UBAHN_API_URL}${path}`, {
109+
headers: { Authorization: `Bearer ${token}` },
110+
params,
111+
validateStatus: (status) => {
112+
if (isOptionRecord && status === 404) {
113+
// If record is not found, it is not an error in scenario where we are checking
114+
// if record exists or not
115+
return true
116+
}
117+
118+
return false
119+
}
120+
})
109121
if (_.isArray(res.data)) {
110122
if (res.data.length === 1) {
111123
return res.data[0]

src/services/ProcessorService.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,7 @@ async function processCreateRecord (record, failedRecord) {
213213
* @returns {Promise}
214214
*/
215215
async function processCreate (message) {
216-
const { resource, status } = message.payload
217-
218-
if (resource !== 'upload') {
219-
logger.info('Ignoring this message since resource is not `upload`')
220-
221-
return
222-
}
216+
const { status } = message.payload
223217

224218
if (status === 'pending') {
225219
try {

0 commit comments

Comments
 (0)