Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pve-manager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
pve-manager
Commits
3f1f9273
Commit
3f1f9273
authored
Jan 26, 2012
by
Dietmar Maurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split out code to convert exceptions to apache handler results
parent
17dd123b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
22 deletions
+23
-22
REST.pm
PVE/REST.pm
+23
-22
No files found.
PVE/REST.pm
View file @
3f1f9273
...
@@ -271,6 +271,24 @@ sub proxy_handler {
...
@@ -271,6 +271,24 @@ sub proxy_handler {
return
OK
;
return
OK
;
}
}
my
$exc_to_res
=
sub
{
my
(
$err
,
$status
)
=
@_
;
$status
=
$status
||
HTTP_INTERNAL_SERVER_ERROR
;
my
$resp
=
{};
if
(
ref
(
$err
)
eq
"
PVE::Exception
")
{
$resp
->
{
status
}
=
$err
->
{
code
}
||
$status
;
$resp
->
{
errors
}
=
$err
->
{
errors
}
if
$err
->
{
errors
};
$resp
->
{
message
}
=
$err
->
{
msg
};
}
else
{
$resp
->
{
status
}
=
$status
;
$resp
->
{
message
}
=
$err
;
}
return
$resp
;
};
sub
rest_handler
{
sub
rest_handler
{
my
(
$rpcenv
,
$clientip
,
$method
,
$abs_uri
,
$rel_uri
,
$ticket
,
$token
)
=
@_
;
my
(
$rpcenv
,
$clientip
,
$method
,
$abs_uri
,
$rel_uri
,
$ticket
,
$token
)
=
@_
;
...
@@ -318,10 +336,7 @@ sub rest_handler {
...
@@ -318,10 +336,7 @@ sub rest_handler {
if
!
$isUpload
&&
(
$euid
!=
0
)
&&
(
$method
ne
'
GET
');
if
!
$isUpload
&&
(
$euid
!=
0
)
&&
(
$method
ne
'
GET
');
};
};
if
(
my
$err
=
$@
)
{
if
(
my
$err
=
$@
)
{
return
{
return
&
$exc_to_res
(
$err
,
HTTP_UNAUTHORIZED
);
status
=>
HTTP_UNAUTHORIZED
,
message
=>
"
$err
",
# always convert exception to string
};
}
}
}
}
...
@@ -363,10 +378,7 @@ sub rest_handler {
...
@@ -363,10 +378,7 @@ sub rest_handler {
# check access permissions
# check access permissions
eval
{
$rpcenv
->
check_api2_permissions
(
$info
->
{
permissions
},
$username
,
$uri_param
);
};
eval
{
$rpcenv
->
check_api2_permissions
(
$info
->
{
permissions
},
$username
,
$uri_param
);
};
if
(
my
$err
=
$@
)
{
if
(
my
$err
=
$@
)
{
return
{
return
&
$exc_to_res
(
$err
,
HTTP_FORBIDDEN
);
status
=>
HTTP_FORBIDDEN
,
message
=>
"
$err
",
# always convert exception to string
};
}
}
if
(
$info
->
{
proxyto
})
{
if
(
$info
->
{
proxyto
})
{
...
@@ -382,10 +394,7 @@ sub rest_handler {
...
@@ -382,10 +394,7 @@ sub rest_handler {
}
}
};
};
if
(
my
$err
=
$@
)
{
if
(
my
$err
=
$@
)
{
return
{
return
&
$exc_to_res
(
$err
);
status
=>
HTTP_INTERNAL_SERVER_ERROR
,
message
=>
"
$err
",
# always convert exception to string
};
}
}
if
(
$remip
)
{
if
(
$remip
)
{
return
{
proxy
=>
$remip
,
proxy_params
=>
$params
};
return
{
proxy
=>
$remip
,
proxy_params
=>
$params
};
...
@@ -415,16 +424,8 @@ sub rest_handler {
...
@@ -415,16 +424,8 @@ sub rest_handler {
$resp
->
{
changes
}
=
$diff
;
$resp
->
{
changes
}
=
$diff
;
}
}
};
};
my
$err
=
$@
;
if
(
my
$err
=
$@
)
{
if
(
$err
)
{
return
&
$exc_to_res
(
$err
);
if
(
ref
(
$err
)
eq
"
PVE::Exception
")
{
$resp
->
{
status
}
=
$err
->
{
code
}
||
HTTP_INTERNAL_SERVER_ERROR
;
$resp
->
{
errors
}
=
$err
->
{
errors
}
if
$err
->
{
errors
};
$resp
->
{
message
}
=
$err
->
{
msg
};
}
else
{
$resp
->
{
status
}
=
HTTP_INTERNAL_SERVER_ERROR
;
$resp
->
{
message
}
=
"
$err
";
}
}
}
$rpcenv
->
set_user
(
undef
);
$rpcenv
->
set_user
(
undef
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment