-
Notifications
You must be signed in to change notification settings - Fork 20
/
errors.lisp
38 lines (27 loc) · 1.34 KB
/
errors.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(in-package :turtl)
(define-condition turtl-error (simple-error)
((msg :accessor error-msg :initarg :msg :initform "")
(code :accessor error-code :initarg :code :initform 500))
(:report (lambda (c s) (format s "~a" (error-msg c))))
(:documentation "A general turtl error."))
(define-condition turtl-error-wrapper (simple-error)
((error :accessor error-error :initarg :error :initform nil)
(function :accessor error-function :initarg :function :initform nil))
(:report (lambda (c s) (format s "Turtl wrapped error: ~a: ~a" (error-function c) (error-error c))))
(:documentation "Used to wrap caught errors and provide more debugging information about them."))
(defmethod jonathan:%to-json ((error turtl-error))
(jonathan:%write-string (format nil "(~a) ~a" (error-code error) (error-msg error))))
(defmethod jonathan:%to-json ((error turtl-error-wrapper))
(jonathan:%to-json (error-error error)))
(define-condition validation-failed (turtl-error)
((code :initform 400)))
(define-condition auth-failed (turtl-error)
((code :initform 401)))
(define-condition insufficient-privileges (turtl-error)
((code :initform 403)))
(define-condition not-found (turtl-error)
((code :initform 404)))
(define-condition item-already-exists (turtl-error)
((code :initform 403)))
(define-condition server-error (turtl-error)
((code :initform 500)))