mirror of
https://github.com/vale981/ement.el
synced 2025-03-04 17:01:39 -05:00
WIP: Log JSON responses to "*Ement API Log*" buffer
See <https://github.com/alphapapa/ement.el/pull/61>.
This commit is contained in:
parent
5dc42521bf
commit
e3d5171103
2 changed files with 17 additions and 2 deletions
17
ement-api.el
17
ement-api.el
|
@ -59,7 +59,7 @@
|
||||||
(else #'ement-api-error) (method 'get)
|
(else #'ement-api-error) (method 'get)
|
||||||
;; FIXME: What's the right term for the URL part after "/_matrix/"?
|
;; FIXME: What's the right term for the URL part after "/_matrix/"?
|
||||||
(endpoint-category "client")
|
(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
|
;; NOTE: Hard to say what the default timeouts
|
||||||
;; should be. Sometimes the matrix.org homeserver
|
;; should be. Sometimes the matrix.org homeserver
|
||||||
;; can get slow and respond a minute or two later.
|
;; can get slow and respond a minute or two later.
|
||||||
|
@ -88,6 +88,21 @@
|
||||||
:as json-read-fn :then then :else else
|
:as json-read-fn :then then :else else
|
||||||
:connect-timeout connect-timeout :timeout timeout :noquery t)))
|
: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)
|
(define-error 'ement-api-error "Ement API error" 'error)
|
||||||
|
|
||||||
(defun ement-api-error (plz-error)
|
(defun ement-api-error (plz-error)
|
||||||
|
|
2
ement.el
2
ement.el
|
@ -616,7 +616,7 @@ a filter ID). When unspecified, the value of
|
||||||
(- (time-to-seconds) sync-start-time)
|
(- (time-to-seconds) sync-start-time)
|
||||||
(file-size-human-readable (buffer-size))))
|
(file-size-human-readable (buffer-size))))
|
||||||
(let ((start-time (time-to-seconds)))
|
(let ((start-time (time-to-seconds)))
|
||||||
(prog1 (json-read)
|
(prog1 (ement-api--json-read-and-log)
|
||||||
(when (ement--sync-messages-p session)
|
(when (ement--sync-messages-p session)
|
||||||
(message "Ement: Reading JSON took %.2f seconds"
|
(message "Ement: Reading JSON took %.2f seconds"
|
||||||
(- (time-to-seconds) start-time)))))))))
|
(- (time-to-seconds) start-time)))))))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue