Plaster

common-lisp
(defmethod create-webhook :around (processor client &rest args) (handler-case (call-next-method) (lisp-pay:api-response-condition (c) (restart-case (apply #'handle-api-condition (make-instance 'webhook-creation) c processor :client client args) (delete-and-retry (&optional c) :report "Webhook already exists, should I delete and retry?" :test (lambda (c) (typep c 'webhook-already-exists)) (delete-webhooks-from-url processor client (getf args :url) nil) (call-next-method)) (clear-our-webhooks-and-retry (&optional c) :report "No more space for webhooks, should I try and delete ours?" :test (lambda (c) (typep c 'no-more-space)) (delete-webhooks-from-url processor client de:*domain* t) (call-next-method)))))) ;;;this determines the type of condition signalled (defmethod handle-api-condition ((caller-classification webhook) condition processor &rest args) (destructuring-bind (&key client url &allow-other-keys) args (cond ((webhook-already-exists-p processor condition) (error 'webhook-already-exists :processor processor :c condition :url url)) ((webhook-limit-exceeded-p processor condition) (error 'no-more-space :client client :c condition :processor processor)) (t (log:error "Couldn't determine webhook condition problem. Please impl") (error 'indeterminate-condition :c condition :processor processor))))) ;;;this is the top level method (defmethod upload-webhook (processor client &rest args) (declare (ignore args)) (handler-bind ((no-more-space (lambda (c) ;; (when (find-restart 'clear-our-webhooks-and-retry) (log:error "Invoking restart 'clear-our-webhooks-and-retry") (invoke-restart 'clear-our-webhooks-and-retry))) (webhook-already-exists (lambda (c) ;; (when (find-restart 'delete-and-retry) (log:error "Invoking restart 'delete-and-retry") (invoke-restart 'delete-and-retry)))) (let* ((url (generate-full-webhook-url client processor)) (hook (create-webhook processor client :events '("*") :description de:*webhook-description* :url url))) (configure-webhook-for-processor processor client hook) processor)))