FU: Add "denied" and "notfound" convenience methods

This commit is contained in:
Yorhel 2025-02-27 14:00:28 +01:00
parent b06cc24826
commit 3662931fc2
2 changed files with 16 additions and 6 deletions

14
FU.pm
View file

@ -352,7 +352,7 @@ sub _do_req($c) {
fu->done;
}
}
fu->error(404);
fu->notfound;
}
1;
};
@ -671,6 +671,8 @@ sub formdata {
sub done { die bless [200,'Done',FU::_caller_info], 'FU::err' }
sub error($,$code,$msg=$code) { die bless [$code,$msg,FU::_caller_info], 'FU::err' }
sub denied { fu->error(403) }
sub notfound { fu->error(404) }
sub status($, $code) { $FU::REQ->{status} = $code }
sub set_body($, $data) {
@ -1137,7 +1139,7 @@ the following is a valid approach to handle user authentication:
};
FU::get '/registered-users-only', sub {
fu->error(403) if !fu->{user};
fu->denied if !fu->{user};
};
In addition to the request information and response generation methods
@ -1266,6 +1268,14 @@ elsewhere, this ends up in running the appropriate C<FU::on_error> handler.
C<$message> is optional and currently only used for logging.
=item fu->denied
Alias for C<< fu->error(403) >>.
=item fu->notfound
Alias for C<< fu->error(404) >>.
=item fu->reset
Reset the response to an empty state, basically undoing all effects of the