Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle expired leetcode session error #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14521,7 +14521,7 @@ const LANG_TO_EXTENSION = {
};
const BASE_URL = "https://leetcode.com";

const delay = (ms) => new Promise((res) => setTimeout(res, ms));
const delay = ms => new Promise(res => setTimeout(res, ms));

function log(message) {
console.log(`[${new Date().toUTCString()}] ${message}`);
Expand Down Expand Up @@ -14756,6 +14756,13 @@ function addToSubmissions(params) {
submissions,
} = params;

if (!response?.data?.data?.submissionList?.submissions) {
throw new Error(
"No LeetCode submissions found. This may be caused by an expired session. " +
"Please check if your LEETCODE_SESSION environment variable is valid and up to date."
);
}

for (const submission of response.data.data.submissionList.submissions) {
submissionTimestamp = Number(submission.timestamp);
if (submissionTimestamp <= lastTimestamp) {
Expand Down Expand Up @@ -14864,6 +14871,7 @@ async function sync(inputs) {
graphql,
{ headers }
);

log(`Successfully fetched submission from LeetCode, offset ${offset}`);
return response;
} catch (exception) {
Expand Down
10 changes: 9 additions & 1 deletion src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const LANG_TO_EXTENSION = {
};
const BASE_URL = "https://leetcode.com";

const delay = (ms) => new Promise((res) => setTimeout(res, ms));
const delay = ms => new Promise(res => setTimeout(res, ms));

function log(message) {
console.log(`[${new Date().toUTCString()}] ${message}`);
Expand Down Expand Up @@ -267,6 +267,13 @@ function addToSubmissions(params) {
submissions,
} = params;

if (!response?.data?.data?.submissionList?.submissions) {
throw new Error(
"No LeetCode submissions found. This may be caused by an expired session. " +
"Please check if your LEETCODE_SESSION environment variable is valid and up to date."
);
}

for (const submission of response.data.data.submissionList.submissions) {
submissionTimestamp = Number(submission.timestamp);
if (submissionTimestamp <= lastTimestamp) {
Expand Down Expand Up @@ -375,6 +382,7 @@ async function sync(inputs) {
graphql,
{ headers }
);

log(`Successfully fetched submission from LeetCode, offset ${offset}`);
return response;
} catch (exception) {
Expand Down