-
Notifications
You must be signed in to change notification settings - Fork 16
/
errors.lisp
64 lines (53 loc) · 2.1 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(defpackage #:jsonrpc/errors
(:use #:cl)
(:import-from #:yason)
(:export #:jsonrpc-error
#:jsonrpc-parse-error
#:jsonrpc-invalid-request
#:jsonrpc-invalid-response
#:jsonrpc-method-not-found
#:jsonrpc-invalid-params
#:jsonrpc-internal-error
#:jsonrpc-server-error
#:jsonrpc-callback-error
#:jsonrpc-error-code
#:jsonrpc-error-message
#:*debug-on-error*))
(in-package #:jsonrpc/errors)
(defvar *debug-on-error* nil
"Open an interactive debugger on any error.")
(define-condition jsonrpc-error (error)
((code :initarg :code
:initform -1
:accessor jsonrpc-error-code)
(message :initarg :message
:initform ""
:accessor jsonrpc-error-message)))
(define-condition jsonrpc-parse-error (jsonrpc-error)
((code :initform -32700)
(message :initform "Parse error")))
(define-condition jsonrpc-invalid-request (jsonrpc-error)
((code :initform -32600)
(message :initform "Invalid Request")))
(define-condition jsonrpc-invalid-response (jsonrpc-error)
((code :initform -32000)
(message :initform "Invalid Response")))
(define-condition jsonrpc-method-not-found (jsonrpc-error)
((code :initform -32601)
(message :initform "Method not found")))
(define-condition jsonrpc-invalid-params (jsonrpc-error)
((code :initform -32602)
(message :initform "Invalid params")))
(define-condition jsonrpc-internal-error (jsonrpc-error)
((code :initform -32603)
(message :initform "Internal error")))
(define-condition jsonrpc-server-error (jsonrpc-error) ())
(define-condition jsonrpc-callback-error (jsonrpc-error) ()
(:report (lambda (condition stream)
(with-slots (message code) condition
(format stream "JSONRPC-CALLBACK-ERROR: ~A (Code=~A)" message code)))))
(defmethod yason:encode ((object jsonrpc-error) &optional stream)
(yason:with-output (stream)
(yason:with-object ()
(yason:encode-object-element "code" (jsonrpc-error-code object))
(yason:encode-object-element "message" (jsonrpc-error-message object)))))