aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.lisp
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2024-08-17 08:05:25 -0700
committercolin <colin@cicadas.surf>2024-08-17 08:05:25 -0700
commit9bf073c54f6a6dc70e01aa032fc53e2f06532275 (patch)
treec525043323768ebdc8160104a1b47ca7b31c661b /src/protocol.lisp
parent26585f3cc99cdc14389cc7bb11686da2c7205a6c (diff)
Add: general http error for use in user applications
Diffstat (limited to 'src/protocol.lisp')
-rw-r--r--src/protocol.lisp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/protocol.lisp b/src/protocol.lisp
index 51c7211..f94364a 100644
--- a/src/protocol.lisp
+++ b/src/protocol.lisp
@@ -42,9 +42,10 @@ that the request has insufficient permissions to evoke the endpoint handler. "))
((wrapped
:reader wrapped
:initarg :error
+ :initform nil
:documentation "A root error that may have caused this error to be signalled."))
(:default-initargs :status-code 400)
- (:documentation "Signalled when the body of a request cannot be deserialized."))
+ (:documentation "Signalled when the body of a request cannot be deserialized, for any reason.."))
(define-condition slot-required (protocol-error)
((mising-slot
@@ -159,3 +160,15 @@ AUTHORIZE while handling endpoint-class instance EP."
(defun get-cookie (name)
"Returns the cookie with name NAME the actively"
(http:cookie-in name))
+
+(define-condition request-error (error)
+ ((content :reader error-content :initarg :content :initform "Bad Request")
+ (mimetype :reader error-content-mimetype :initarg :mimetype :initform "text/plain")
+ (code :reader status-code :initarg :code :initform 400)))
+
+(defmethod protocol-error-result ((err request-error))
+ (values (error-content err) (error-content-mimetype err)))
+
+(defun err (&key (code 400) (content "Bad Request") (mimetype "text/plain"))
+ "Signal an error and abort request."
+ (error 'request-error :code code :content content :mimetype mimetype))