Apply clack-error-middleware
This commit is contained in:
parent
cdb60c8eca
commit
8d209a1bb4
5 changed files with 13 additions and 34 deletions
1
qlfile
1
qlfile
|
@ -7,3 +7,4 @@ git ningle-fbr https://github.com/skyizwhite/ningle-fbr.git
|
|||
git lack-mw https://github.com/skyizwhite/lack-mw.git
|
||||
git trivial-backtrace https://github.com/hraban/trivial-backtrace.git
|
||||
ql cl-dotenv
|
||||
ql clack-errors
|
||||
|
|
|
@ -38,3 +38,7 @@
|
|||
(:class qlot/source/ql:source-ql
|
||||
:initargs (:%version :latest)
|
||||
:version "ql-2018-10-18"))
|
||||
("clack-errors" .
|
||||
(:class qlot/source/ql:source-ql
|
||||
:initargs (:%version :latest)
|
||||
:version "ql-2019-08-13"))
|
||||
|
|
11
src/app.lisp
11
src/app.lisp
|
@ -7,10 +7,12 @@
|
|||
#:configure)
|
||||
(:import-from #:ningle-fbr
|
||||
#:set-routes)
|
||||
(:import-from #:hp/middlewares/recoverer
|
||||
#:*recoverer*)
|
||||
(:import-from #:lack-mw
|
||||
#:*trim-trailing-slash*)
|
||||
(:import-from #:clack-errors
|
||||
#:*clack-error-middleware*)
|
||||
(:import-from #:hp/env
|
||||
#:hp-env)
|
||||
(:import-from #:hp/renderer)
|
||||
(:export #:*app*))
|
||||
(in-package #:hp/app)
|
||||
|
@ -18,7 +20,10 @@
|
|||
(defparameter *app*
|
||||
(let ((app (make-app)))
|
||||
(set-routes app :system :hp :target-dir-path "routes")
|
||||
(install-middleware app *recoverer*)
|
||||
(install-middleware app (lambda (app)
|
||||
(funcall *clack-error-middleware*
|
||||
app
|
||||
:debug (string= (hp-env) "dev"))))
|
||||
(install-middleware app *trim-trailing-slash*)
|
||||
(static-path app "/img/" "static/img/")
|
||||
(static-path app "/style/" "static/style/")
|
||||
|
|
0
src/middlewares/.keep
Normal file
0
src/middlewares/.keep
Normal file
|
@ -1,31 +0,0 @@
|
|||
(defpackage #:hp/middlewares/recoverer
|
||||
(:use #:cl
|
||||
#:hsx)
|
||||
(:import-from #:trivial-backtrace
|
||||
#:print-backtrace)
|
||||
(:import-from #:hp/env
|
||||
#:hp-env)
|
||||
(:export #:*recoverer*))
|
||||
(in-package #:hp/middlewares/recoverer)
|
||||
|
||||
(defun error-page (condition)
|
||||
(hsx
|
||||
(html :lang "ja"
|
||||
(head
|
||||
(title "Internal Server Error"))
|
||||
(body
|
||||
(main
|
||||
(h1 "500 Internal Server Error")
|
||||
(when (string= (hp-env) "dev")
|
||||
(hsx
|
||||
(pre
|
||||
(code (print-backtrace condition :output nil))))))))))
|
||||
|
||||
(defparameter *recoverer*
|
||||
(lambda (app)
|
||||
(lambda (env)
|
||||
(handler-case
|
||||
(funcall app env)
|
||||
(error (c)
|
||||
`(500 (:content-type "text/html; charset=utf-8")
|
||||
(,(hsx:render-to-string (error-page c)))))))))
|
Loading…
Add table
Add a link
Reference in a new issue