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

Commit 93c5028

Browse files
committed
Handle if dbissue is null.
1 parent 064ee61 commit 93c5028

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

services/IssueService.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ async function handleIssueAssignment(event, issue, force = false) {
194194
try {
195195
dbIssue = await ensureChallengeExists(event, issue);
196196

197+
if (!dbIssue) {
198+
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
199+
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
200+
// Handle it for rescheduling.
201+
await eventService.handleEventGracefully(event, issue, err);
202+
return;
203+
}
204+
197205
// Handle multiple assignees. TC-X allows only one assignee.
198206
if (event.data.issue.assignees && event.data.issue.assignees.length > 1) {
199207
const comment = 'Topcoder-X only supports a single assignee on a ticket to avoid issues with payment';
@@ -302,6 +310,14 @@ async function handleIssueUpdate(event, issue) {
302310
try {
303311
dbIssue = await ensureChallengeExists(event, issue, false);
304312

313+
if (!dbIssue) {
314+
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
315+
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
316+
// Handle it for rescheduling.
317+
await eventService.handleEventGracefully(event, issue, err);
318+
return;
319+
}
320+
305321
if (dbIssue.title === issue.title &&
306322
dbIssue.body === issue.body &&
307323
dbIssue.prizes.length === issue.prizes.length &&
@@ -345,6 +361,15 @@ async function handleIssueClose(event, issue) {
345361
let dbIssue;
346362
try {
347363
dbIssue = await ensureChallengeExists(event, issue);
364+
365+
if (!dbIssue) {
366+
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
367+
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
368+
// Handle it for rescheduling.
369+
await eventService.handleEventGracefully(event, issue, err);
370+
return;
371+
}
372+
348373
event.dbIssue = dbIssue;
349374

350375
// if the issue has payment success or payment pending status, we'll ignore this process.
@@ -633,6 +658,15 @@ async function handleIssueUnAssignment(event, issue) {
633658
let dbIssue;
634659
try {
635660
dbIssue = await ensureChallengeExists(event, issue);
661+
662+
if (!dbIssue) {
663+
const err = errors.internalDependencyError(`Can't find the issue in DB. It's not found or not accessible`);
664+
// The dbissue is not found, the db is not accessible, or the issue is still in creation process.
665+
// Handle it for rescheduling.
666+
await eventService.handleEventGracefully(event, issue, err);
667+
return;
668+
}
669+
636670
if (dbIssue.assignee) {
637671
const assigneeUserId = gitHelper.getUserIdByLogin(event, dbIssue.assignee);
638672
logger.debug(`Looking up TC handle of git user: ${assigneeUserId}`);

0 commit comments

Comments
 (0)