Skip to content
Snippets Groups Projects
Commit 5ce4fce1 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2813853 by Wim Leers: RequestHandler has its own error handling rather...

Issue #2813853 by Wim Leers: RequestHandler has its own error handling rather than leaving it to KernelEvents::EXCEPTION event subscribers
parent 63cad2c6
No related branches found
No related tags found
No related merge requests found
......@@ -103,11 +103,7 @@ protected function assertNormalizationEdgeCases($method, Url $url, array $reques
// DX: 400 when incorrect entity type bundle is specified.
$response = $this->request($method, $url, $request_options);
// @todo Uncomment, remove next 3 in https://www.drupal.org/node/2813853.
// $this->assertResourceErrorResponse(400, 'No entity type(s) specified', $response);
$this->assertSame(400, $response->getStatusCode());
$this->assertSame([static::$mimeType], $response->getHeader('Content-Type'));
$this->assertSame($this->serializer->encode(['error' => 'No entity type(s) specified'], static::$format), (string) $response->getBody());
$this->assertResourceErrorResponse(400, 'No entity type(s) specified', $response);
unset($normalization['_links']['type']);
......@@ -116,11 +112,7 @@ protected function assertNormalizationEdgeCases($method, Url $url, array $reques
// DX: 400 when no entity type bundle is specified.
$response = $this->request($method, $url, $request_options);
// @todo Uncomment, remove next 3 in https://www.drupal.org/node/2813853.
// $this->assertResourceErrorResponse(400, 'The type link relation must be specified.', $response);
$this->assertSame(400, $response->getStatusCode());
$this->assertSame([static::$mimeType], $response->getHeader('Content-Type'));
$this->assertSame($this->serializer->encode(['error' => 'The type link relation must be specified.'], static::$format), (string) $response->getBody());
$this->assertResourceErrorResponse(400, 'The type link relation must be specified.', $response);
}
}
......
......@@ -10,7 +10,7 @@
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
......@@ -107,9 +107,7 @@ public function handle(RouteMatchInterface $route_match, Request $request) {
}
}
catch (UnexpectedValueException $e) {
$error['error'] = $e->getMessage();
$content = $serializer->serialize($error, $format);
return new Response($content, 400, array('Content-Type' => $request->getMimeType($format)));
throw new BadRequestHttpException($e->getMessage());
}
}
else {
......
......@@ -532,12 +532,7 @@ public function testPost() {
// DX: 400 when unparseable request body.
$response = $this->request('POST', $url, $request_options);
// @todo Uncomment, remove next 3 in https://www.drupal.org/node/2813853.
// $this->assertResourceErrorResponse(400, 'Syntax error', $response);
$this->assertSame(400, $response->getStatusCode());
$this->assertSame([static::$mimeType], $response->getHeader('Content-Type'));
$this->assertSame($this->serializer->encode(['error' => 'Syntax error'], static::$format), (string) $response->getBody());
$this->assertResourceErrorResponse(400, 'Syntax error', $response);
$request_options[RequestOptions::BODY] = $parseable_invalid_request_body;
......@@ -724,11 +719,7 @@ public function testPatch() {
// DX: 400 when unparseable request body.
$response = $this->request('PATCH', $url, $request_options);
// @todo Uncomment, remove next 3 in https://www.drupal.org/node/2813853.
// $this->assertResourceErrorResponse(400, 'Syntax error', $response);
$this->assertSame(400, $response->getStatusCode());
$this->assertSame([static::$mimeType], $response->getHeader('Content-Type'));
$this->assertSame($this->serializer->encode(['error' => 'Syntax error'], static::$format), (string) $response->getBody());
$this->assertResourceErrorResponse(400, 'Syntax error', $response);
......@@ -968,11 +959,7 @@ protected function assertNormalizationEdgeCases($method, Url $url, array $reques
// DX: 400 when incorrect entity type bundle is specified.
// @todo Change to 422 in https://www.drupal.org/node/2827084.
$response = $this->request($method, $url, $request_options);
// @todo use this commented line instead of the 3 lines thereafter once https://www.drupal.org/node/2813853 lands.
// $this->assertResourceErrorResponse(400, '"bad_bundle_name" is not a valid bundle type for denormalization.', $response);
$this->assertSame(400, $response->getStatusCode());
$this->assertSame([static::$mimeType], $response->getHeader('Content-Type'));
$this->assertSame($this->serializer->encode(['error' => '"bad_bundle_name" is not a valid bundle type for denormalization.'], static::$format), (string) $response->getBody());
$this->assertResourceErrorResponse(400, '"bad_bundle_name" is not a valid bundle type for denormalization.', $response);
}
......@@ -983,11 +970,7 @@ protected function assertNormalizationEdgeCases($method, Url $url, array $reques
// DX: 400 when no entity type bundle is specified.
// @todo Change to 422 in https://www.drupal.org/node/2827084.
$response = $this->request($method, $url, $request_options);
// @todo use this commented line instead of the 3 lines thereafter once https://www.drupal.org/node/2813853 lands.
// $this->assertResourceErrorResponse(400, 'A string must be provided as a bundle value.', $response);
$this->assertSame(400, $response->getStatusCode());
$this->assertSame([static::$mimeType], $response->getHeader('Content-Type'));
$this->assertSame($this->serializer->encode(['error' => 'A string must be provided as a bundle value.'], static::$format), (string) $response->getBody());
$this->assertResourceErrorResponse(400, 'A string must be provided as a bundle value.', $response);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment