Permalink
Browse files

- improved error messages

- handle empty Json request gracefully.
  • Loading branch information...
1 parent 4a3b2ac commit c428f9361963cb5aec35f591888b1a83bf5e0ebc Igor Lankin committed Mar 5, 2012
View
@@ -8,13 +8,17 @@ Git commit: ?????
Bugfixes
~~~~~~~~
+- Handle empty Json request gracefully.
+ (iigorr)
- Merged pull request #128 - Don't access scriptlet.HttpScriptletRequest
params public property, use setters and getters instead
(cconstandachi)
Features
~~~~~~~~
-- Changed text.parser.generic.ParseException to contain the parse error messages. Not only their messages.
+- Changed webservices.rest.server.RestDataCaster methods to be non-static.
+ (iigorr)
+- Added possibility to handle error in webservices.rest.server.rpc.RestHttpScriptlet using webservices.rest.server.RestErrorFormatter
(iigorr)
- Changed text.parser.generic.ParseException to contain the parse error messages. Not only their messages.
(iigorr)
@@ -4,6 +4,11 @@
* $Id$
*/
+ uses(
+ 'scriptlet.HttpScriptletException',
+ 'peer.http.HttpConstants'
+ );
+
/**
* Factory for HTTP request adapters
*
@@ -27,8 +32,9 @@ public static function forRequest($request) {
return XPClass::forName('webservices.rest.server.transport.EmptyHttpRequestAdapter');
}
- if (!isset($map[$request->getHeader('Content-Type')])) throw new IllegalArgumentException(
- 'The content type is not supported: '.$request->getHeader('Content-Type')
+ if (!isset($map[$request->getHeader('Content-Type')])) throw new HttpScriptletException(
+ 'The content type is not supported: '.$request->getHeader('Content-Type'),
+ HttpConstants::STATUS_UNSUPPORTED_MEDIA_TYPE
);
return XPClass::forName($map[$request->getHeader('Content-Type')]);
@@ -4,6 +4,11 @@
* $Id$
*/
+ uses(
+ 'scriptlet.HttpScriptletException',
+ 'peer.http.HttpConstants'
+ );
+
/**
* Factory for HTTP response adapters
*
@@ -24,8 +29,9 @@ public static function forRequest($request) {
'application/json' => 'webservices.rest.server.transport.JsonHttpResponseAdapter'
);
- if (!isset($map[$request->getHeader('Accept')])) throw new IllegalArgumentException(
- 'The accept type is not supported: '.$request->getHeader('Accept')
+ if (!isset($map[$request->getHeader('Accept')])) throw new HttpScriptletException(
+ 'The accept type is not supported: '.$request->getHeader('Accept'),
+ HttpConstants::STATUS_NOT_ACCEPTABLE
);
return XPClass::forName($map[$request->getHeader('Accept')]);
@@ -6,9 +6,12 @@
uses(
'webservices.rest.server.transport.AbstractHttpRequestAdapter',
- 'webservices.json.JsonDecoder'
+ 'webservices.json.JsonDecoder',
+ 'scriptlet.HttpScriptletException',
+ 'peer.http.HttpConstants'
);
+
/**
* The JSON representation of HTTP request
*
@@ -23,12 +26,12 @@ class JsonHttpRequestAdapter extends AbstractHttpRequestAdapter {
* @return var[]
*/
public function getData() {
- if('' === $this->request->getData())
- return null;
+ if ('' === $this->request->getData()) return NULL;
+
try {
return create(new JsonDecoder())->decode($this->request->getData());
- } catch(JsonException $e) {
- throw new FormatException('Could not process JSON data. ', $e);
+ } catch (JsonException $e) {
+ throw new HttpScriptletException('Could not process JSON data.', HttpConstants::STATUS_BAD_REQUEST, $e);
}
}
}
@@ -29,7 +29,7 @@ public function setUp() {
* Test wrong type
*
*/
- #[@test, @expect('lang.IllegalArgumentException')]
+ #[@test, @expect('scriptlet.HttpScriptletException')]
public function wrongContentType() {
$this->request->addHeader('Content-Type', 'something/wrong');
@@ -29,7 +29,7 @@ public function setUp() {
* Test wrong type
*
*/
- #[@test, @expect('lang.IllegalArgumentException')]
+ #[@test, @expect('scriptlet.HttpScriptletException')]
public function wrongContentType() {
$this->request->addHeader('Content-Type', 'something/wrong');

0 comments on commit c428f93

Please sign in to comment.