WIP: Log JSON responses to "*Ement API Log*" buffer

See <https://github.com/alphapapa/ement.el/pull/61>.
This commit is contained in:
Adam Porter 2022-04-02 11:10:49 -05:00
parent 5dc42521bf
commit e3d5171103
2 changed files with 17 additions and 2 deletions

View file

@ -59,7 +59,7 @@
(else #'ement-api-error) (method 'get)
;; FIXME: What's the right term for the URL part after "/_matrix/"?
(endpoint-category "client")
(json-read-fn #'json-read)
(json-read-fn #'ement-api--json-read-and-log)
;; NOTE: Hard to say what the default timeouts
;; should be. Sometimes the matrix.org homeserver
;; can get slow and respond a minute or two later.
@ -88,6 +88,21 @@
:as json-read-fn :then then :else else
:connect-timeout connect-timeout :timeout timeout :noquery t)))
(defun ement-api--json-read-and-log ()
(let ((json-buffer (current-buffer)))
(with-current-buffer (get-buffer-create "*Ement API Log*")
(save-excursion
(goto-char (point-max))
(let ((beg (point))
end)
(insert-buffer-substring json-buffer)
(setf end (point))
(insert "\n")
(save-restriction
(narrow-to-region beg end)
(json-pretty-print-buffer))))))
(json-read))
(define-error 'ement-api-error "Ement API error" 'error)
(defun ement-api-error (plz-error)

View file

@ -616,7 +616,7 @@ a filter ID). When unspecified, the value of
(- (time-to-seconds) sync-start-time)
(file-size-human-readable (buffer-size))))
(let ((start-time (time-to-seconds)))
(prog1 (json-read)
(prog1 (ement-api--json-read-and-log)
(when (ement--sync-messages-p session)
(message "Ement: Reading JSON took %.2f seconds"
(- (time-to-seconds) start-time)))))))))