tkf / emacs-request

Request.el -- Easy HTTP request for Emacs Lisp
http://tkf.github.com/emacs-request/
GNU General Public License v3.0
617 stars 91 forks source link

[Feature request]: Silence "[error] request--callback: peculiar error" when aborting without setting custom variables #226

Open daanturo opened 1 month ago

daanturo commented 1 month ago

Currently when using request-abort, an error will be echoed:

[error] request--callback: peculiar error

This cannot be disabled without setting request-message-level (If I understand correctly).

Reproduce

(progn
  (let* ((req
          (request
           "http://httpbin.org/post"
           :type "POST"
           :data '(("key" . "value"))
           :error 'ignore
           :parser 'json-read
           :success (cl-function 'ignore))))
    ;; I tried let-binding here, but callbacks are asynchronous so they aren't
    ;; affected
    (dlet ((request-message-level -1))
      (request-abort req))
    ""))

Observed

[error] request--callback: peculiar error appears in the echo area and *Message*.

Expected

Silent

Is it possible to abort the running request, without informing the user? My package depends of request, so setq-ing an user option without their consent is not polite. Maybe adding more optional arguments to request-abort to silence errors?

dickmao commented 1 month ago

Here's one conspicuously bad way of doing it:

(request-abort
 (let ((req (request "http://httpbin.org/post"
          :type "POST"
          :data '(("key" . "value"))
          :error (lambda (&rest _args) (message "got here"))
          :parser #'json-read
          :success #'ignore)))
   (prog1 req
     (add-function
      :around
      (process-sentinel (get-buffer-process
             (request-response--buffer req)))
      (lambda (f &rest args)
    (let ((request-message-level -1))
      (apply f args)))))))
daanturo commented 1 month ago

Here's one conspicuously bad way of doing it:

(request-abort
 (let ((req (request "http://httpbin.org/post"
        :type "POST"
        :data '(("key" . "value"))
        :error (lambda (&rest _args) (message "got here"))
        :parser #'json-read
        :success #'ignore)))
   (prog1 req
     (add-function
      :around
      (process-sentinel (get-buffer-process
           (request-response--buffer req)))
      (lambda (f &rest args)
  (let ((request-message-level -1))
    (apply f args)))))))

Thank you that works for me.

But I really hope that there would be an official support, like https://github.com/tkf/emacs-request/commit/506500e5e5e0eb4ed5e94812ea6376d1f9933863.