Skip to content

Commit e416ee5

Browse files
fix: pulljobs failing would crash server
1 parent e31a0c1 commit e416ee5

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/server/pullJobScheduler.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,15 @@ const fetchRecordsServiceToService = (
162162
// eslint-disable-next-line @typescript-eslint/no-use-before-define
163163
insertRecords(json2.result, pullJob);
164164
}
165+
})
166+
.catch((err) => {
167+
throw err;
168+
logger.error(err.message, { stack: err.stack });
165169
});
166170
}
171+
})
172+
.catch((err) => {
173+
logger.error(err.message, { stack: err.stack });
167174
});
168175
}
169176
// Generic case
@@ -178,9 +185,14 @@ const fetchRecordsServiceToService = (
178185
.then((res) => res.json())
179186
.then((json) => {
180187
if (json) {
188+
const data = pullJob.path ? get(json, pullJob.path) : json;
189+
if (!data) return;
181190
// eslint-disable-next-line @typescript-eslint/no-use-before-define
182-
insertRecords(json, pullJob);
191+
insertRecords(data, pullJob);
183192
}
193+
})
194+
.catch((err) => {
195+
logger.error(err.message, { stack: err.stack });
184196
});
185197
}
186198
};
@@ -194,12 +206,15 @@ const fetchRecordsPublic = (pullJob: PullJob): void => {
194206
const apiConfiguration: ApiConfiguration = pullJob.apiConfiguration;
195207
logger.info(`Execute pull job operation: ${pullJob.name}`);
196208
fetch(apiConfiguration.endpoint + pullJob.url, { method: 'get' })
197-
.then((res) => res.json())
209+
.then((res) => res?.json())
198210
.then((json) => {
199-
if (json && json[pullJob.path]) {
200-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
201-
insertRecords(json[pullJob.path], pullJob);
202-
}
211+
const data = pullJob.path ? get(json, pullJob.path) : json;
212+
if (!data) return;
213+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
214+
insertRecords(data, pullJob);
215+
})
216+
.catch((err) => {
217+
logger.error(err.message, { stack: err.stack });
203218
});
204219
};
205220

0 commit comments

Comments
 (0)