Skip to content

Commit eb1d21e

Browse files
authored
Minor fixes
1 parent c8cafbb commit eb1d21e

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

core/errors.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
# Error Handling
1+
# Errors Handling
22

33
API Platform comes with a powerful error system. It handles excepted (such as faulty JSON documents sent by the
44
client or validation errors) as well as unexpected errors (PHP exceptions and errors).
5-
API Platform automatically send the appropriate HTTP status code to the client: `400` for expected errors, `500` for
6-
unexpected ones. It also provides a description of the respecting [the Hydra specification](http://www.hydra-cg.com/spec/latest/core/#description-of-http-status-codes-and-errors)
7-
or the [RFC 7807](https://tools.ietf.org/html/rfc7807) depending of the format selected during the [content negotiation](content-negotiation.md).
5+
API Platform automatically sends the appropriate HTTP status code to the client: `400` for expected errors, `500` for
6+
unexpected ones. It also provides a description of the error in [the Hydra error format](http://www.hydra-cg.com/spec/latest/core/#description-of-http-status-codes-and-errors)
7+
or in the format described in the [RFC 7807](https://tools.ietf.org/html/rfc7807), depending of the format selected during the [content negotiation](content-negotiation.md).
88

99
## Converting PHP Exceptions to HTTP Errors
1010

1111
The framework also allows to configure the HTTP status code sent to the clients when custom exceptions are thrown.
1212

13-
In the following example, we will throw explain to throw a domain exception from the business layer of the application and
14-
configure API Platform to convert it to a `404 Not Found` error. Let's create a this domain exception and the service throwing
15-
it:
13+
In the following example, we throw a domain exception from the business layer of the application and
14+
configure API Platform to convert it to a `404 Not Found` error:
1615

1716
```php
1817
<?php
@@ -63,14 +62,14 @@ final class ProductManager implements EventSubscriberInterface
6362
}
6463
```
6564

66-
If you use the standard distribution of API Platform, the event listener will be automatically registered. If you use a
65+
If you use the standard distribution of API Platform, this event listener will be automatically registered. If you use a
6766
custom installation, [learn how to register listeners](events.md).
6867

6968
Then, configure the framework to catch `AppBundle\Exception\ProductNotFoundException` exceptions and convert them in `404`
7069
errors:
7170

7271
```yaml
73-
# app/config/config.yml
72+
# config/packages/api_platform.yaml
7473
api_platform:
7574
# ...
7675
exception_to_status:
@@ -82,7 +81,7 @@ api_platform:
8281
```
8382
8483
Any type of `Exception` can be thrown, API Platform will convert it to a Symfony's `HttpException`. The framework also takes
85-
care to serialize the error description according to the request format. For instance, if the API should respond in JSON-LD,
84+
care of serializing the error description according to the request format. For instance, if the API should respond in JSON-LD,
8685
the error will be returned in this format as well:
8786

8887
`GET /products/1234`
@@ -94,4 +93,4 @@ the error will be returned in this format as well:
9493
"hydra:title": "An error occurred",
9594
"hydra:description": "The product \"1234\" does not exist."
9695
}
97-
```
96+
```

0 commit comments

Comments
 (0)