Function: majutsu-gerrit-rest-request

majutsu-gerrit-rest-request is a natively compiled function defined in majutsu-gerrit-rest.el.

Signature

(majutsu-gerrit-rest-request METHOD ENDPOINT &optional DATA SPEC PARAMS HEADERS)

Documentation

Perform Gerrit REST METHOD request to ENDPOINT using plz.

Return a plist (:status STATUS :body BODY :url URL). DATA is encoded as JSON unless it is already a string. PARAMS is an alist query string and HEADERS is a list of strings or (NAME . VALUE) cons cells.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-gerrit-rest.el
;;;; Public request API

(defun majutsu-gerrit-rest-request (method endpoint &optional data spec params headers)
  "Perform Gerrit REST METHOD request to ENDPOINT using `plz'.

Return a plist (:status STATUS :body BODY :url URL).  DATA is encoded as
JSON unless it is already a string.  PARAMS is an alist query string and
HEADERS is a list of strings or (NAME . VALUE) cons cells."
  (let* ((spec (majutsu-gerrit-rest--require-spec spec))
         (method (intern (downcase (format "%s" method))))
         (url (majutsu-gerrit-rest--build-url spec endpoint params))
         (body (majutsu-gerrit-rest--body-string data))
         (headers (majutsu-gerrit-rest--headers spec body headers)))
    (when majutsu-gerrit-rest-debug
      (message "majutsu-gerrit-rest: %s %S" method url))
    (condition-case err
        (let ((response (plz method url
                          :headers headers
                          :body body
                          :as 'response
                          :then 'sync)))
          (list :status (plz-response-status response)
                :body (plz-response-body response)
                :url url))
      ;; `plz' signals `plz-http-error' (HTTP 4xx/5xx) as
      ;; (signal 'plz-http-error (list "HTTP error" <plz-error>))
      ;; and `plz-curl-error' (transport/TLS) likewise.  Both inherit from
      ;; `plz-error', so catching the parent unifies them.  The actual
      ;; `plz-error' struct is the second element of the condition data,
      ;; not the data list itself.
      (plz-error
       (let* ((plz-err (cl-find-if #'plz-error-p (cdr err)))
              (response (when plz-err (plz-error-response plz-err)))
              (status (when response (plz-response-status response)))
              (body (when response (plz-response-body response))))
         (list :status (or status 0)
               :body (or body "")
               :url url))))))