added some error checking and moved some more
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9552 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
52b66f3617
commit
3c9b7294e2
@ -64,10 +64,23 @@ sub genRequest{
|
||||
my $xml = XMLout($request, RootName=>'xcatrequest',NoAttr=>1,KeyAttr=>[]);
|
||||
}
|
||||
|
||||
#default format
|
||||
my $format = 'html';
|
||||
|
||||
#data formatters. To add one simple copy the format of an existing one
|
||||
# and add it to this hash
|
||||
my %formatters = ('html' => \&wrapHtml,
|
||||
'json' => \&wrapJson,
|
||||
'xml' => \&wrapXml,
|
||||
);
|
||||
|
||||
if($q->param('format'))
|
||||
{
|
||||
$format = $q->param('format');
|
||||
if(!exists $formatters{$format}){
|
||||
sendStatusMsg($STATUS_BAD_REQUEST, "The format '$format' is not valid");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
#if no resource was specified
|
||||
@ -1302,13 +1315,6 @@ sub jobsHandler{
|
||||
}
|
||||
|
||||
|
||||
#data formatters. To add one simple copy the format of an existing one
|
||||
# and add it to this hash
|
||||
my %formatters = ('html' => \&wrapHtml,
|
||||
'json' => \&wrapJson,
|
||||
'xml' => \&wrapXml,
|
||||
);
|
||||
|
||||
#all data wrapping and writing is funneled through here
|
||||
sub wrapData{
|
||||
my @data = shift;
|
||||
@ -1326,6 +1332,15 @@ sub wrapJson
|
||||
print to_json($json);
|
||||
}
|
||||
|
||||
sub wrapJsonOld
|
||||
{
|
||||
my @data = shift;
|
||||
print header('application/json');
|
||||
my $json;
|
||||
$json->{'data'} = \@data;
|
||||
print to_json($json);
|
||||
}
|
||||
|
||||
sub wrapHtml
|
||||
{
|
||||
my $item;
|
||||
@ -1338,8 +1353,12 @@ sub wrapHtml
|
||||
#print $q->p("dumping in wrapHtml ".Dumper(@response));
|
||||
foreach my $data (@response){
|
||||
if(@$data[0]->{error}){
|
||||
#not sure if we can be more specific with status codes or if this is the right choice
|
||||
sendStatusMsg($STATUS_NOT_ACCEPTABLE, @$data[0]->{error}[0]);
|
||||
if(@$data[0]->{error}[0] =~ /Permission denied/ || @$data[0]->{error}[0] =~ /Authentication failure/){
|
||||
sendStatusMsg($STATUS_UNAUTH, @$data[0]->{error}[0]);
|
||||
}
|
||||
else{
|
||||
sendStatusMsg($STATUS_NOT_ACCEPTABLE, @$data[0]->{error}[0]);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
else{
|
||||
|
Loading…
x
Reference in New Issue
Block a user