263 | 263 |
{ my ($disp, $options, $reason, $message) = @_;
|
264 | 264 |
|
265 | 265 |
my $fatal_handler = sub {
|
266 | |
my $req = $_dsl->request;
|
267 | |
_forward_home( $_dsl, $_[0] )
|
268 | |
if $req && ($req->uri ne '/' || !$req->is_get);
|
|
266 |
|
|
267 |
# Check whether this fatal message has been caught, in which case we
|
|
268 |
# don't want to redirect
|
|
269 |
return _message_add($_[0])
|
|
270 |
if exists $options->{is_fatal} && !$options->{is_fatal};
|
|
271 |
|
|
272 |
my $req = $_dsl->request
|
|
273 |
or return;
|
|
274 |
|
|
275 |
# Don't forward if it's a GET request to the error page, as it will
|
|
276 |
# cause a recursive loop. In this case, do nothing, and let dancer
|
|
277 |
# handle it.
|
|
278 |
# return not needed because of Return::MultiLevel hack, but let's
|
|
279 |
# leave it in anyway in hope.
|
|
280 |
return _forward_home($_dsl, $_[0])
|
|
281 |
if $req->uri ne $_settings->{forward_url} || !$req->is_get;
|
|
282 |
|
|
283 |
return;
|
269 | 284 |
};
|
270 | 285 |
|
271 | 286 |
$message->reason($reason);
|
|
278 | 293 |
# This could have already been caught by the process
|
279 | 294 |
# subroutine, in which case we should continue running
|
280 | 295 |
# of the program. In all other cases, we should bail
|
281 | |
# out. With the former, the exception will have been
|
282 | |
# re-thrown as a non-fatal exception, so check that.
|
283 | |
, ERROR => sub {
|
284 | |
return _message_add( $_[0] )
|
285 | |
if exists $options->{is_fatal} && !$options->{is_fatal};
|
286 | |
|
287 | |
my $req = $_dsl->request;
|
288 | |
return _forward_home( $_dsl, $_[0] )
|
289 | |
if $req && ($req->uri ne '/' || !$req->is_get);
|
290 | |
|
291 | |
return;
|
292 | |
}
|
|
296 |
# out.
|
|
297 |
, ERROR => $fatal_handler
|
293 | 298 |
|
294 | 299 |
# 'FAULT', 'ALERT', 'FAILURE', 'PANIC'
|
295 | |
# All these are fatal errors. Display error to user, but
|
296 | |
# forward home so that we can reload. However, don't if
|
297 | |
# it's a GET request to the home, as it will cause a recursive
|
298 | |
# loop. In this case, do nothing, and let dancer handle it.
|
|
300 |
# All these are fatal errors.
|
299 | 301 |
, FAULT => $fatal_handler
|
300 | 302 |
, ALERT => $fatal_handler
|
301 | 303 |
, FAILURE => $fatal_handler
|