Skip to content

Commit 0aaa911

Browse files
deviantintegralamitaibu
authored andcommittedJan 22, 2015
Fix missing entities returning HTTP 500 instead of a 4XX
1 parent d1076c6 commit 0aaa911

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
 

‎exceptions/RestfulUnprocessableEntityException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Contains RestfulUnprocessableEntityException
66
*/
77

8-
class RestfulUnprocessableEntityException extends Exception {
8+
class RestfulUnprocessableEntityException extends RestfulException {
99

1010
/**
1111
* Defines the HTTP error code.

‎tests/RestfulExceptionHandleTestCase.test

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Contains RestfulExceptionHandleTestCase
66
*/
77

8-
class RestfulExceptionHandleTestCase extends DrupalWebTestCase {
8+
class RestfulExceptionHandleTestCase extends RestfulCurlBaseTestCase {
99

1010
public static function getInfo() {
1111
return array(
@@ -38,4 +38,16 @@ class RestfulExceptionHandleTestCase extends DrupalWebTestCase {
3838
$this->assertResponse('400', 'Correct HTTP code.');
3939
}
4040

41+
/**
42+
* Test when an entity is not found that a 4XX is returned instead of 500.
43+
*/
44+
function testEntityNotFoundDelivery() {
45+
$url = 'api/v1.0/articles/1';
46+
$result = $this->httpRequest($url);
47+
$body = drupal_json_decode($result['body']);
48+
$this->assertEqual($result['code'], '422', format_string('422 status code sent for @url url.', array('@url' => $url)));
49+
$this->assertTrue(strpos($result['headers'], 'application/problem+json;'), '"application/problem+json" found in invalid request.');
50+
$this->assertEqual($body['title'], 'The entity ID 1 for Articles does not exist.', 'Correct error message.');
51+
}
52+
4153
}

0 commit comments

Comments
 (0)
Please sign in to comment.