~taiju/kintai-el

4cc708bd484dbc73a3e3b4e82d05788cb4129a1a — Taiju HIGASHI 1 year, 6 months ago 9ddbcc0
Add error handling.
1 files changed, 14 insertions(+), 6 deletions(-)

M kintai.el
M kintai.el => kintai.el +14 -6
@@ 16,6 16,7 @@
;;; Code:

(require 'url)
(require 'json)

(defgroup kintai nil
  "Posting kintai to a specific Slack channel."


@@ 55,14 56,21 @@ MSG is the message to post."
         (url-request-data (format "channel=%s&text=%s"
                                   (url-hexify-string kintai-slack-channel)
                                   (url-hexify-string msg)))
         (cbargs nil)
         (silent nil)
         (inhibit-cookies t))
    (url-retrieve kintai--slack-endpoint
                  (lambda (status) (message "posted \"%s\" to %s" msg kintai-slack-channel))
                  cbargs
                  silent
                  inhibit-cookies)))
    (with-current-buffer
        (url-retrieve-synchronously kintai--slack-endpoint
                                    silent
                                    inhibit-cookies)
      (goto-char (point-min))
      (re-search-forward "^$")
      (let* ((body (json-read))
             (err (assq 'error body)))
        (if err
            (error "failed post: status=%s, error=%s"
                   url-http-response-status
                   (cdr err))
          (message "posted \"%s\" to %s" msg kintai-slack-channel))))))

;;;###autoload
(defun kintai-start ()