( defmacro with-protect-to-json ( &body body ) ` ( handler-case ` ( 200 ( :content-type "application/json" ) ( , ( jojo:to-json ( progn ,@ body )))) ( error ( e ) ` ( 500 ( :content-type "application/json" ) ( , ( jojo:to-json ( list :|error| ( format nil "~A" e )))))))) ( defun asc ( key alist ) ( cdr ( assoc key alist :test #' string= ))) ;; URLパラメータの割り算をする ( defroute "/numerator/:numer/denominator/:denom" ( params :method :GET ) ( with-protect-to-json ( list :answer ( / ( parse-integer ( asc :numer params )) ( parse-integer ( asc :denom params )))))) ;; 9を3で割った結果を返す ( dex:get "http://localhost:5000/numerator/9/denominator/3" ) ;; "{\"ANSWER\":3}" ;; 200 ;; ゼロ除算 ( dex:get "http://localhost:5000/numerator/1/denominator/0" ) ;; debugger invoked on a DEXADOR.ERROR:HTTP-REQUEST-INTERNAL-SERVER-ERROR in thread ;; #<THREAD "main thread" RUNNING {1001928083}>: ;; An HTTP request to "http://localhost:5000/numerator/1/denominator/0" returned 500 internal server error. ;; {"error":"arithmetic error DIVISION-BY-ZERO signalled

Operation was (/ 1 0)."}