irongit

A Neovim plugin enabling you to solve LeetCode problems.

refactor: session expiration handler (#135)

* refactor: don't force session expiration

* fix: grammar
Marcinauthored committed by GitHub
parent 43256e9commit 2076e26732de77b94ce9e09dec2edaa1a4739f61Browse files

3 files changed, +12 -4

+1-1lua/leetcode/api/auth.lua
@@ -36,7 +36,7 @@ function Auth.handle(res, err)
3636 err = {}
3737
3838 if (not config.is_cn and auth.id == vim.NIL) or (config.is_cn and auth.slug == vim.NIL) then
39- err.msg = "Session expired?"
39+ err.msg = "Cookie expired?"
4040 elseif not auth.is_signed_in then
4141 err.msg = "Sign-in failed"
4242 elseif not auth.is_verified then
+8-1lua/leetcode/api/statistics.lua
@@ -135,9 +135,16 @@ function statistics.streak(cb)
135135 if err then
136136 return cb(nil, err)
137137 end
138+
138139 local data = res.data
139140 local streak = data["streakCounter"]
140- cb(streak)
141+
142+ if streak == vim.NIL then
143+ err = { msg = "Failed to load streak counter" }
144+ cb(nil, err)
145+ else
146+ cb(streak)
147+ end
141148 end,
142149 })
143150 end
+3-2lua/leetcode/api/utils.lua
@@ -151,8 +151,9 @@ function utils.check_err(err)
151151
152152 if err.status then
153153 if err.status == 401 or err.status == 403 then
154- require("leetcode.command").expire()
155- err.msg = "Session expired? Enter a new cookie to keep using `leetcode.nvim`"
154+ -- require("leetcode.command").expire()
155+ err.msg =
156+ "Your cookie may have expired, or LeetCode has temporarily restricted API access"
156157 end
157158 end
158159