mirror of
https://github.com/vale981/cl-telegram-bot
synced 2025-03-04 17:21:41 -05:00
Treat bad response status as error
This commit is contained in:
parent
168c5edd15
commit
9153e00599
1 changed files with 15 additions and 7 deletions
|
@ -71,12 +71,18 @@
|
|||
|
||||
(defun make-request (b name options &key (streamp nil))
|
||||
"Perform HTTP request to 'name API method with 'options JSON-encoded object."
|
||||
(let* ((results (multiple-value-list
|
||||
(drakma:http-request
|
||||
(concatenate 'string (endpoint b) name)
|
||||
:method :post
|
||||
:want-stream streamp
|
||||
:content-type "application/json"
|
||||
:content (json:encode-json-alist-to-string options)))
|
||||
:content (json:encode-json-alist-to-string options))))
|
||||
(status (cadr results))
|
||||
(reason (car (last results))))
|
||||
(when (<= 400 status 599)
|
||||
(error 'request-error :what (format nil "request to ~A returned ~A (~A)" name status reason)))
|
||||
(apply 'values results)))
|
||||
|
||||
(defun access (update &rest args)
|
||||
"Access update field. update.first.second. ... => (access update 'first 'second ...). Nil if unbound."
|
||||
|
@ -115,7 +121,9 @@
|
|||
(decode (map 'string #'code-char object)))
|
||||
|
||||
(define-condition request-error (error)
|
||||
((what :initarg :what :reader what)))
|
||||
((what :initarg :what :reader what))
|
||||
(:report (lambda (condition stream)
|
||||
(format stream "Request error: ~A" (what condition)))))
|
||||
|
||||
(defmacro find-json-symbol (sym)
|
||||
`(find-symbol (symbol-name ,sym) json:*json-symbols-package*))
|
||||
|
|
Loading…
Add table
Reference in a new issue