From 41bd459f275c5b5527f1332349e6a39fea88a24e Mon Sep 17 00:00:00 2001 From: Branislav Bujisic Date: Fri, 9 Nov 2018 16:53:40 +0100 Subject: [PATCH] Replace RestfulUnprocessableEntityException with RestfulNotFoundException if entity cannot be loaded. --- plugins/restful/RestfulEntityBase.php | 2 +- tests/RestfulExceptionHandleTestCase.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/restful/RestfulEntityBase.php b/plugins/restful/RestfulEntityBase.php index 212697a5..172fed6b 100644 --- a/plugins/restful/RestfulEntityBase.php +++ b/plugins/restful/RestfulEntityBase.php @@ -1162,7 +1162,7 @@ protected function isValidEntity($op, $entity_id) { ); if (!$entity = entity_load_single($entity_type, $entity_id)) { - throw new RestfulUnprocessableEntityException(format_string('The entity ID @id for @resource does not exist.', $params)); + throw new RestfulNotFoundException(format_string('The entity ID @id for @resource does not exist.', $params)); } list(,, $bundle) = entity_extract_ids($entity_type, $entity); diff --git a/tests/RestfulExceptionHandleTestCase.test b/tests/RestfulExceptionHandleTestCase.test index e96d413a..1a21f57d 100644 --- a/tests/RestfulExceptionHandleTestCase.test +++ b/tests/RestfulExceptionHandleTestCase.test @@ -45,7 +45,7 @@ class RestfulExceptionHandleTestCase extends RestfulCurlBaseTestCase { $url = 'api/v1.0/articles/1'; $result = $this->httpRequest($url); $body = drupal_json_decode($result['body']); - $this->assertEqual($result['code'], '422', format_string('422 status code sent for @url url.', array('@url' => $url))); + $this->assertEqual($result['code'], '404', format_string('404 status code sent for @url url.', array('@url' => $url))); $this->assertTrue(strpos($result['headers'], 'application/problem+json;'), '"application/problem+json" found in invalid request.'); $this->assertEqual($body['title'], 'The entity ID 1 for Articles does not exist.', 'Correct error message.'); }