Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Add FlattenExceptionNormalizer / Fix messenger used with the serializer component #33650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Renamed normalized properties names according to RFC 7807
  • Loading branch information
skalpa committed Sep 24, 2019
commit c704b361b0572e2f8f2107a0d9b9cc93d4d8faee
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ public function normalize($object, $format = null, array $context = [])
}
/* @var FlattenException $object */

return [
'message' => $object->getMessage(),
$normalized = [
'detail' => $object->getMessage(),
'code' => $object->getCode(),
'status_code' => $object->getStatusCode(),
'headers' => $object->getHeaders(),
'class' => $object->getClass(),
'file' => $object->getFile(),
Expand All @@ -46,6 +45,11 @@ public function normalize($object, $format = null, array $context = [])
'trace' => $object->getTrace(),
'trace_as_string' => $object->getTraceAsString(),
];
if (null !== $status = $object->getStatusCode()) {
$normalized['status'] = $status;
}

return $normalized;
}

/**
Expand All @@ -70,9 +74,9 @@ public function denormalize($data, $type, $format = null, array $context = [])

$object = new FlattenException();

$object->setMessage($data['message'] ?? null);
$object->setMessage($data['detail'] ?? null);
$object->setCode($data['code'] ?? null);
$object->setStatusCode($data['status_code'] ?? null);
$object->setStatusCode($data['status'] ?? null);
$object->setClass($data['class'] ?? null);
$object->setFile($data['file'] ?? null);
$object->setLine($data['line'] ?? null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ public function testNormalize(FlattenException $exception): void
$normalized = $this->normalizer->normalize($exception);
$previous = null === $exception->getPrevious() ? null : $this->normalizer->normalize($exception->getPrevious());

$this->assertSame($exception->getMessage(), $normalized['message']);
$this->assertSame($exception->getMessage(), $normalized['detail']);
$this->assertSame($exception->getCode(), $normalized['code']);
$this->assertSame($exception->getStatusCode(), $normalized['status_code']);
if (null !== $exception->getStatusCode()) {
$this->assertSame($exception->getStatusCode(), $normalized['status']);
} else {
$this->assertArrayNotHasKey('status', $normalized);
}
$this->assertSame($exception->getHeaders(), $normalized['headers']);
$this->assertSame($exception->getClass(), $normalized['class']);
$this->assertSame($exception->getFile(), $normalized['file']);
Expand Down Expand Up @@ -98,15 +102,15 @@ public function testDenormalizeValidData(): void
$this->assertNull($exception->getTraceAsString());

$normalized = [
'message' => 'Something went foobar.',
'detail' => 'Something went foobar.',
'code' => 42,
'status_code' => 404,
'status' => 404,
'headers' => ['Content-Type' => 'application/json'],
'class' => \get_class($this),
'file' => 'foo.php',
'line' => 123,
'previous' => [
'message' => 'Previous exception',
'detail' => 'Previous exception',
'code' => 0,
],
'trace' => [
Expand All @@ -119,9 +123,9 @@ public function testDenormalizeValidData(): void
$exception = $this->normalizer->denormalize($normalized, FlattenException::class);

$this->assertInstanceOf(FlattenException::class, $exception);
$this->assertSame($normalized['message'], $exception->getMessage());
$this->assertSame($normalized['detail'], $exception->getMessage());
$this->assertSame($normalized['code'], $exception->getCode());
$this->assertSame($normalized['status_code'], $exception->getStatusCode());
$this->assertSame($normalized['status'], $exception->getStatusCode());
$this->assertSame($normalized['headers'], $exception->getHeaders());
$this->assertSame($normalized['class'], $exception->getClass());
$this->assertSame($normalized['file'], $exception->getFile());
Expand All @@ -130,7 +134,7 @@ public function testDenormalizeValidData(): void
$this->assertSame($normalized['trace_as_string'], $exception->getTraceAsString());

$this->assertInstanceOf(FlattenException::class, $previous = $exception->getPrevious());
$this->assertSame($normalized['previous']['message'], $previous->getMessage());
$this->assertSame($normalized['previous']['detail'], $previous->getMessage());
$this->assertSame($normalized['previous']['code'], $previous->getCode());
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.