From dafcefda9169d67c31a107b21fa84bbe01f07098 Mon Sep 17 00:00:00 2001 From: kawre Date: Sat, 26 Oct 2024 15:56:27 +0200 Subject: [PATCH 1/2] refactor: don't force session expiration --- lua/leetcode/api/auth.lua | 2 +- lua/leetcode/api/statistics.lua | 9 ++++++++- lua/leetcode/api/utils.lua | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lua/leetcode/api/auth.lua b/lua/leetcode/api/auth.lua index a677aad..cef2f94 100644 --- a/lua/leetcode/api/auth.lua +++ b/lua/leetcode/api/auth.lua @@ -36,7 +36,7 @@ function Auth.handle(res, err) err = {} if (not config.is_cn and auth.id == vim.NIL) or (config.is_cn and auth.slug == vim.NIL) then - err.msg = "Session expired?" + err.msg = "Cookie expired?" elseif not auth.is_signed_in then err.msg = "Sign-in failed" elseif not auth.is_verified then diff --git a/lua/leetcode/api/statistics.lua b/lua/leetcode/api/statistics.lua index adac765..6ce24db 100644 --- a/lua/leetcode/api/statistics.lua +++ b/lua/leetcode/api/statistics.lua @@ -135,9 +135,16 @@ function statistics.streak(cb) if err then return cb(nil, err) end + local data = res.data local streak = data["streakCounter"] - cb(streak) + + if streak == vim.NIL then + err = { msg = "Failed to load streak counter" } + cb(nil, err) + else + cb(streak) + end end, }) end diff --git a/lua/leetcode/api/utils.lua b/lua/leetcode/api/utils.lua index 0121074..f2b1b91 100644 --- a/lua/leetcode/api/utils.lua +++ b/lua/leetcode/api/utils.lua @@ -152,8 +152,8 @@ function utils.check_err(err) if err.status then if err.status == 401 or err.status == 403 then - require("leetcode.command").expire() - err.msg = "Session expired? Enter a new cookie to keep using `leetcode.nvim`" + -- require("leetcode.command").expire() + err.msg = "Your cookie may have expired or LeetCode has restricted its API access" end end From ab2e5ccb06552e3d4208d1a0bfc4c36dbf76cca6 Mon Sep 17 00:00:00 2001 From: kawre Date: Sat, 26 Oct 2024 17:11:34 +0200 Subject: [PATCH 2/2] fix: grammar --- lua/leetcode/api/utils.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/leetcode/api/utils.lua b/lua/leetcode/api/utils.lua index f2b1b91..455caf0 100644 --- a/lua/leetcode/api/utils.lua +++ b/lua/leetcode/api/utils.lua @@ -153,7 +153,8 @@ function utils.check_err(err) if err.status then if err.status == 401 or err.status == 403 then -- require("leetcode.command").expire() - err.msg = "Your cookie may have expired or LeetCode has restricted its API access" + err.msg = + "Your cookie may have expired, or LeetCode has temporarily restricted API access" end end