Commit bb10bfa7 authored by catch's avatar catch
Browse files

Issue #2512668 by MattA, martin107, dawehner: Dblog rest plugin throws...

Issue #2512668 by MattA, martin107, dawehner: Dblog rest plugin throws exception with incorrect parameters
parent de27f197
......@@ -9,7 +9,7 @@
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
......@@ -36,7 +36,10 @@ class DBLogResource extends ResourceBase {
* @return \Drupal\rest\ResourceResponse
* The response containing the log entry.
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* Thrown when the log entry was not found.
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
* Thrown when no log entry was provided.
*/
public function get($id = NULL) {
if ($id) {
......@@ -49,6 +52,6 @@ public function get($id = NULL) {
throw new NotFoundHttpException(t('Log entry with ID @id was not found', array('@id' => $id)));
}
throw new HttpException(t('No log entry ID was provided'));
throw new BadRequestHttpException(t('No log entry ID was provided'));
}
}
......@@ -59,5 +59,11 @@ public function testWatchdog() {
$this->assertResponse(404);
$decoded = Json::decode($response);
$this->assertEqual($decoded['error'], 'Log entry with ID 9999 was not found', 'Response message is correct.');
// Make a bad request (a true malformed request would never be a route match).
$response = $this->httpRequest(Url::fromRoute('rest.dblog.GET.' . $this->defaultFormat, ['id' => 0, '_format' => $this->defaultFormat]), 'GET');
$this->assertResponse(400);
$decoded = Json::decode($response);
$this->assertEqual($decoded['error'], 'No log entry ID was provided', 'Response message is correct.');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment