Skip to content

Commit

Permalink
fix: error handling in claiming process
Browse files Browse the repository at this point in the history
Introduced a single try-catch block to the transcript claiming function
to ensure all errors are caught and handled uniformly. This replaces
inconsistent catch blocks and addresses actions that were previously
 missing error handling, improving reliability and error management.
  • Loading branch information
kouloumos authored and Extheoisah committed May 28, 2024
1 parent 3e17a63 commit 7e0c66e
Showing 1 changed file with 56 additions and 57 deletions.
113 changes: 56 additions & 57 deletions src/components/tables/QueueTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,72 +156,71 @@ const QueueTable = () => {
if (session?.user?.id) {
setSelectedTranscriptId(transcriptId);

// Fork repo
const forkResult = await axios.post("/api/github/fork");
const owner = forkResult.data.owner.login;
try {
// Fork repo
const forkResult = await axios.post("/api/github/fork");
const owner = forkResult.data.owner.login;

const env_owner =
process.env.NEXT_PUBLIC_VERCEL_ENV === "development"
? forkResult.data.owner.login
: upstreamOwner;
const env_owner =
process.env.NEXT_PUBLIC_VERCEL_ENV === "development"
? forkResult.data.owner.login
: upstreamOwner;

let branchUrl;
let branchUrl;

if (transcript && transcript.transcriptUrl) {
try {
await axios
.post("/api/github/newBranch", {
ghSourcePath: transcript.transcriptUrl,
owner,
env_owner,
})
.then((res) => {
branchUrl = res.data.branchUrl;
})
.catch((err) => {
throw err;
});
} catch (err: any) {
console.error(err);
throw new Error(err.message);
if (transcript && transcript.transcriptUrl) {
const result = await axios.post("/api/github/newBranch", {
ghSourcePath: transcript.transcriptUrl,
owner,
env_owner,
})
branchUrl = result.data.branchUrl
}
}

// Claim transcript
claimTranscript.mutate(
{ userId: session.user.id, transcriptId, branchUrl },
{
onSuccess: async (data) => {
try {
const reviewId = data.id;
if (!reviewId) {
throw new Error("failed to claim transcript");
}
// Claim transcript
claimTranscript.mutate(
{ userId: session.user.id, transcriptId, branchUrl },
{
onSuccess: async (data) => {
try {
const reviewId = data.id;
if (!reviewId) {
throw new Error("failed to claim transcript");
}

if (data instanceof Error) {
await retryLoginAndClaim(transcriptId);
return;
if (data instanceof Error) {
await retryLoginAndClaim(transcriptId);
return;
}
if (multipleStatusData.length > 0) {
router.push(`/reviews/${data.id}`);
} else {
router.push(`/reviews/${data.id}?first_review=true`);
}
} catch (err) {
console.error(err);
}
if (multipleStatusData.length > 0) {
router.push(`/reviews/${data.id}`);
} else {
router.push(`/reviews/${data.id}?first_review=true`);
}
} catch (err) {
console.error(err);
}
},
},

onError: (err) => {
const error = err as Error;
setSelectedTranscriptId(-1);
toast({
status: "error",
title: error?.message,
});
},
onError: (err) => {
throw err
},
}
);
} catch (error: any) {
// handles all errors from claiming process
let errorTitle = error.message
if (error.response) {
// for errors coming from axios requests
// we display our custom error message
errorTitle = error.response.data.message
}
);
setSelectedTranscriptId(-1);
toast({
status: "error",
title: errorTitle,
});
}
} else {
await retryLoginAndClaim(transcriptId);
}
Expand Down

0 comments on commit 7e0c66e

Please sign in to comment.