From 8c77914e758abe3f540587dfc323b45c3387ceb6 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 20 Jan 2012 07:05:16 +0100 Subject: [PATCH] new helper raise_perm_exc --- data/PVE/Exception.pm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/data/PVE/Exception.pm b/data/PVE/Exception.pm index 8004d05..63b3843 100755 --- a/data/PVE/Exception.pm +++ b/data/PVE/Exception.pm @@ -21,7 +21,7 @@ use overload 'cmp' => sub { return "$a" cmp "$b"; # compare as string }; -@EXPORT_OK = qw(raise raise_param_exc); +@EXPORT_OK = qw(raise raise_param_exc raise_perm_exc); sub new { my ($class, $msg, %param) = @_; @@ -53,6 +53,25 @@ sub raise { die $exc; } +sub raise_perm_exc { + my ($what) = @_; + + my $param = { code => HTTP_FORBIDDEN }; + + my $msg = "Permission check failed"; + + $msg .= " ($what)" if $what; + + my $exc = PVE::Exception->new("$msg\n", %$param); + + my ($pkg, $filename, $line) = caller; + + $exc->{filename} = $filename; + $exc->{line} = $line; + + die $exc; +} + sub is_param_exc { my ($self) = @_; -- 2.39.2