Skip to content

refactor: session expiration handler #135

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

Merged
merged 2 commits into from
Oct 26, 2024
Merged
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
2 changes: 1 addition & 1 deletion lua/leetcode/api/auth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lua/leetcode/api/statistics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lua/leetcode/api/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ 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 temporarily restricted API access"
end
end

Expand Down