Skip to content

Commit af05392

Browse files
committed
Improve error handler
1 parent 40f2732 commit af05392

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

helm-qiita.el

+21-21
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,26 @@ Use `helm-qiita-url' if URL is nil."
154154
"--header" ,(concat "Authorization: Bearer " helm-qiita-access-token)
155155
,(if url url helm-qiita-url)))
156156
proc)
157-
(unless (get-buffer-process http-buffer-name)
158-
(if (get-buffer http-buffer-name)
159-
(kill-buffer http-buffer-name))
160-
(unless url ;; 1st page
161-
(if (get-buffer work-buffer-name)
162-
(kill-buffer work-buffer-name))
163-
(get-buffer-create work-buffer-name))
164-
(helm-qiita-http-debug-start)
165-
(setq proc (apply 'start-process
166-
proc-name
167-
http-buffer-name
168-
helm-qiita-curl-program
169-
curl-args))
170-
(set-process-sentinel proc 'helm-qiita-http-request-sentinel))))
157+
(unless url ;; 1st page
158+
(if (get-buffer work-buffer-name)
159+
(kill-buffer work-buffer-name))
160+
(get-buffer-create work-buffer-name))
161+
(helm-qiita-http-debug-start)
162+
(setq proc (apply 'start-process
163+
proc-name
164+
http-buffer-name
165+
helm-qiita-curl-program
166+
curl-args))
167+
(set-process-sentinel proc 'helm-qiita-http-request-sentinel)))
171168

172169
(defun helm-qiita-http-request-sentinel (process _event)
173170
"Receive a response of `helm-qiita-http-request'.
174171
PROCESS is a http-request process.
175172
_EVENT is a string describing the type of event."
176-
(ignore-errors
177-
(helm-qiita-handle-http-response process)))
173+
(condition-case nil
174+
(helm-qiita-handle-http-response process)
175+
(error
176+
(kill-buffer helm-qiita-http-buffer-name))))
178177

179178
(defun helm-qiita-handle-http-response (process)
180179
"Handle a response of `helm-qiita-http-request'.
@@ -189,14 +188,15 @@ If next-link is exist, continue to request it."
189188
(setq response (json-read-from-string
190189
(buffer-substring-no-properties
191190
(+ (helm-qiita-point-of-separator) 1) (point-max)))))
191+
(kill-buffer helm-qiita-http-buffer-name)
192192
(with-current-buffer (get-buffer helm-qiita-work-buffer-name)
193193
(goto-char (point-max))
194194
(dotimes (i (length response))
195-
(setq stock (aref response i))
196-
(insert (format "%s %s [href:%s]\n"
197-
(helm-qiita-stock-title stock)
198-
(helm-qiita-stock-format-tags stock)
199-
(helm-qiita-stock-url stock))))
195+
(setq stock (aref response i))
196+
(insert (format "%s %s [href:%s]\n"
197+
(helm-qiita-stock-title stock)
198+
(helm-qiita-stock-format-tags stock)
199+
(helm-qiita-stock-url stock))))
200200
(if next-link
201201
(helm-qiita-http-request next-link)
202202
(write-region (point-min) (point-max) helm-qiita-file)))))

0 commit comments

Comments
 (0)