Dragonfly errors | Dragonfly web framework
What happens when a user visits the following link?
Go ahead and click it. I can wait.
That was an error 404 page, the page that's displayed when all routes failed to match.
Dragonfly uses the DF:display-error function to show these pages. You can too! Here's a quick example of how to use it:
Pretty simple huh?
By default Dragonfly does not show that fancy page you just saw, instead it stores a default (and boring) error template in the symbol DF:ERROR_TEMPLATE. It will use that to display all errors unless it can find an alternative.
For example, if this page didn't exist and no alternative 404 page was found, here's what you'd see:
The requested URL /dragonfly_errors resulted in error 404 Not Found.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
How do you specify an alternative?
Custom Error Templates
Dragonfly will check inside VIEW_PATHS to see if a view with the error number exists. In other words, a call to (display-error 500) results in a check for:
(file? (Dragonfly:view-path "500"))
If it exists, it will be displayed instead of ERROR_TEMPLATE.
To see this site's 500 page, click here.
Checking the dragonfly.log
Dragonfly defines an error handler DF:error-handler, that's called whenever an error is generated (for example, by a call to throw-error). You can specify your own handler with a plugin.
The default handler makes use of Dragonfly's logging functions to log the stack-trace to the file specified by LOG_FILE_PATH in config.lsp, and then it will call (display-error 500).
If you don't want to publicly show the stack trace in your error 500 template, you don't have to. Just remember to check the log for it. You'll probably also want to setup a cron script roll over the log every now and then to prevent it from getting too large.
Dragonfly's logging facilities are defined dragonfly-framework/lib/log.lsp, check the api for more info.