A Neovim plugin enabling you to solve LeetCode problems.
refactor: session expiration handler (#135)
* refactor: don't force session expiration * fix: grammar
3 files changed, +12 -4
+1-1lua/leetcode/api/auth.lua
| @@ -36,7 +36,7 @@ function Auth.handle(res, err) | ||
| 36 | 36 | err = {} |
| 37 | 37 | |
| 38 | 38 | 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?" | |
| 40 | 40 | elseif not auth.is_signed_in then |
| 41 | 41 | err.msg = "Sign-in failed" |
| 42 | 42 | elseif not auth.is_verified then |
+8-1lua/leetcode/api/statistics.lua
| @@ -135,9 +135,16 @@ function statistics.streak(cb) | ||
| 135 | 135 | if err then |
| 136 | 136 | return cb(nil, err) |
| 137 | 137 | end |
| 138 | + | |
| 138 | 139 | local data = res.data |
| 139 | 140 | 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 | |
| 141 | 148 | end, |
| 142 | 149 | }) |
| 143 | 150 | end |
+3-2lua/leetcode/api/utils.lua
| @@ -151,8 +151,9 @@ function utils.check_err(err) | ||
| 151 | 151 | |
| 152 | 152 | if err.status then |
| 153 | 153 | 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" | |
| 156 | 157 | end |
| 157 | 158 | end |
| 158 | 159 |