Error-handling for invalid requests etc
This commit is contained in:
parent
b34ca289a3
commit
5a2562fd07
|
@ -71,12 +71,21 @@ in the docstring of SERVER."
|
||||||
type "application/activity+json")))))
|
type "application/activity+json")))))
|
||||||
|
|
||||||
|
|
||||||
|
(define-condition invalid-acct-uri (error) ()
|
||||||
|
(:documentation "Thrown when a user@host acct URI is expected, but is lacking a user or host potion."))
|
||||||
|
|
||||||
|
|
||||||
(defun resource-user-host (resource)
|
(defun resource-user-host (resource)
|
||||||
"Given a queried RESOURCE, return a list of its contained user and host."
|
"Given a queried RESOURCE, return a list of its contained user and host."
|
||||||
(let* ((sans-acct (if (str:starts-with-p "acct:" resource)
|
(let* ((sans-acct (if (str:starts-with-p "acct:" resource)
|
||||||
(subseq resource 5)
|
(subseq resource 5)
|
||||||
resource)))
|
resource))
|
||||||
(str:split #\@ sans-acct)))
|
(user-host (str:split #\@ sans-acct)))
|
||||||
|
(if (or (not (eq (length user-host) 2))
|
||||||
|
(str:emptyp (car user-host))
|
||||||
|
(str:emptyp (cadr user-host)))
|
||||||
|
(error 'invalid-acct-uri :message "Invalid acct resource")
|
||||||
|
user-host)))
|
||||||
|
|
||||||
|
|
||||||
(defun filter-link-rels (rels link-plists)
|
(defun filter-link-rels (rels link-plists)
|
||||||
|
@ -109,14 +118,25 @@ the RESOURCE and RELS parameters from a Webfinger HTTP request, return the
|
||||||
response JSON in Clack’s format.
|
response JSON in Clack’s format.
|
||||||
This can be used if you don’t want to wrap your server with SERVER, and would
|
This can be used if you don’t want to wrap your server with SERVER, and would
|
||||||
rather handle the Webfinger path yourself."
|
rather handle the Webfinger path yourself."
|
||||||
(list 200
|
(list
|
||||||
'(:content-type "text/plain")
|
200
|
||||||
(list (format nil "~A~%"
|
'(:content-type "text/plain")
|
||||||
(apply #'user-json
|
(list
|
||||||
(filter-user-info-rels
|
(format
|
||||||
rels
|
nil "~A"
|
||||||
(apply user-info-func
|
(handler-case
|
||||||
(resource-user-host resource))))))))
|
(if (not resource)
|
||||||
|
"\"No resource specified\""
|
||||||
|
(or (apply #'user-json
|
||||||
|
(filter-user-info-rels
|
||||||
|
rels
|
||||||
|
(apply user-info-func
|
||||||
|
(resource-user-host resource))))
|
||||||
|
"\"Couldn't find user\""))
|
||||||
|
(invalid-acct-uri ()
|
||||||
|
"\"Invalid acct URI\"")
|
||||||
|
(error (any-error)
|
||||||
|
(format nil "\"Server error: ~A\"" any-error)))))))
|
||||||
|
|
||||||
|
|
||||||
(defun server (env user-info-func &optional (clack-app nil))
|
(defun server (env user-info-func &optional (clack-app nil))
|
||||||
|
|
Ŝarĝante…
Reference in New Issue