From 9bf073c54f6a6dc70e01aa032fc53e2f06532275 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 17 Aug 2024 08:05:25 -0700 Subject: Add: general http error for use in user applications --- src/protocol.lisp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/protocol.lisp') 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)) -- cgit v1.2.3