Responses as JSON

This commit is contained in:
Niten 2020-11-15 14:06:03 -08:00
parent 7590531d03
commit 120b820d8e
1 changed files with 15 additions and 3 deletions

View File

@ -40,15 +40,20 @@
(defmethod render-result ((res result/success)) (defmethod render-result ((res result/success))
(with-slots (message msg-id) res (with-slots (message msg-id) res
(cl-json:encode-json
`((STATUS . "OK")
(MESSAGE . ,message)
(MSGID . ,msg-id)))
(let ((msg (if message (format nil ":~A" message) "")) (let ((msg (if message (format nil ":~A" message) ""))
(msgid (if msg-id (format nil " (~A)" msg-id) ""))) (msgid (if msg-id (format nil " (~A)" msg-id) "")))
(format nil "OK~A~A" msgid msg)))) (format nil "OK~A~A" msgid msg))))
(defmethod render-result ((res result/error)) (defmethod render-result ((res result/error))
(with-slots (message msg-id) res (with-slots (message msg-id) res
(let ((msg (if message (format nil ":~A" message) "")) (cl-json:encode-json
(msgid (if msg-id (format nil " (~A)" msg-id) ""))) `((STATUS . "ERROR")
(format nil "ERROR~A~A" msgid msg)))) (MESSAGE . ,message)
(MSGID . ,msg-id)))))
(defgeneric parse-message (sender service api-version message msg-id) (defgeneric parse-message (sender service api-version message msg-id)
(:documentation "Given an incoming message, turn it into the appropriate request.")) (:documentation "Given an incoming message, turn it into the appropriate request."))
@ -122,3 +127,10 @@
(format nil "backplane-~A" (machine-instance)) (format nil "backplane-~A" (machine-instance))
:mechanism :sasl-plain) :mechanism :sasl-plain)
backplane)))) backplane))))
;;;; nope...capture the var name and make sure it gets closed, but still pass it in
(defmacro with-backplane (backplane &rest ops)
(let ((bp-sym (gensym)))
`(let ((,bp-sym ,backplane))
(unwind-protect (progn ,@ops)
(cl-xmpp:disconnect ,bp-sym)))))