Skip to content

Commit

Permalink
doc: error guide emove useless configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Oct 10, 2024
1 parent 3ca5991 commit 02ac74a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions docs/guides/error-resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
// tags: design, state
// ---

// Note that we use the following configuration:
// ```
// api_platform:
// defaults:
// rfc_7807_compliant_errors: true
// ```

namespace App\ApiResource {
use ApiPlatform\Metadata\ErrorResource;
use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
Expand All @@ -25,12 +18,12 @@ class MyDomainException extends \Exception implements ProblemExceptionInterface
{
public function getType(): string
{
return 'teapot';
return '/errors/418';
}

public function getTitle(): ?string
{
return null;
return 'Teapot error';
}

public function getStatus(): ?int
Expand All @@ -47,6 +40,8 @@ public function getInstance(): ?string
{
return null;
}

public string $myCustomField = 'I usually prefer coffee.';
}

use ApiPlatform\Metadata\ApiResource;
Expand Down Expand Up @@ -84,13 +79,18 @@ final class BookTest extends ApiTestCase

public function testBookDoesNotExists(): void
{
static::createClient()->request('GET', '/books/1', options: ['headers' => ['accept' => 'application/ld+json']]);
$r = static::createClient()->request('GET', '/books/1', options: ['headers' => ['accept' => 'application/ld+json']]);
// We expect the status code returned by our `getStatus` and the message inside `detail`
// for security reasons 500 errors will get their "detail" changed by our Error Provider
// you can override this by looking at the [Error Provider guide](/docs/guides/error-provider).
$this->assertResponseStatusCodeSame(418);
$this->assertJsonContains([
'@id' => '/my_domain_exceptions',
'@type' => 'MyDomainException',
'type' => '/errors/418',
'title' => 'Teapot error',
'detail' => 'I am teapot',
'myCustomField' => 'I usually prefer coffee.'
]);
}
}
Expand Down

0 comments on commit 02ac74a

Please sign in to comment.