From 3c9b7294e26b96a55f17c3202635ef874b3ba0f5 Mon Sep 17 00:00:00 2001 From: cjhardee Date: Tue, 10 May 2011 20:18:30 +0000 Subject: [PATCH] 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 --- xCAT-wsapi/xcatws.cgi | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/xCAT-wsapi/xcatws.cgi b/xCAT-wsapi/xcatws.cgi index f35b2f52e..cd05eb95a 100755 --- a/xCAT-wsapi/xcatws.cgi +++ b/xCAT-wsapi/xcatws.cgi @@ -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{