Skip to content

Commit b2f2b76

Browse files
committed
Show error info when use leetcode-try, add request error handler
See: kaiwk#3
1 parent afde29c commit b2f2b76

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

leetcode.el

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,25 @@ Return a list of rows, each row is a vector:
453453
(leetcode--check-submission
454454
interpret-id slug-title
455455
(lambda (res)
456-
(let ((answer (aref (alist-get 'code_answer res) 0)))
456+
(let ((status-code (alist-get 'status_code res))
457+
(status-msg (alist-get 'status_msg res)))
457458
(with-current-buffer res-buf
458-
(insert (concat "Output:\n" answer "\n\n"))))
459-
(leetcode--loading-mode -1)))))))))
459+
(insert "Output:\n")
460+
(cond
461+
((eq status-code 10)
462+
(insert (aref (alist-get 'code_answer res) 0)))
463+
((eq status-code 14)
464+
(insert status-msg))
465+
((eq status-code 15)
466+
(insert status-msg)
467+
(insert "\n\n")
468+
(insert (alist-get 'full_runtime_error res)))
469+
((eq status-code 20)
470+
(insert status-msg)
471+
(insert "\n\n")
472+
(insert (alist-get 'full_compile_error res))))
473+
(insert "\n\n")
474+
(leetcode--loading-mode -1)))))))))))
460475

461476
(defun leetcode--check-submission (submission-id slug-title cb)
462477
"Polling to check submission detail.
@@ -477,7 +492,12 @@ request success."
477492
(lambda (&key data &allow-other-keys)
478493
(if (equal (alist-get 'state data) "SUCCESS")
479494
(funcall cb data)
480-
(leetcode--check-submission submission-id slug-title cb))))))
495+
(leetcode--check-submission submission-id slug-title cb))))
496+
:error
497+
(cl-function
498+
(lambda (&rest args &key error-thrown &allow-other-keys)
499+
(leetcode-global-loading-mode -1)
500+
(message "LeetCode Login ERROR: %S" error-thrown)))))
481501

482502
(defun leetcode--solving-layout ()
483503
"Specify layout for solving problem.

0 commit comments

Comments
 (0)