|
1 | | -# Default types |
| 1 | +# Default Types |
2 | 2 |
|
3 | | -When you raise your own exceptions implementing `Zend\ProblemDetails\Exception\ProblemDetailsExceptionInterface` you |
4 | | -will always be in control of all the properties returned as part of the response payload, naming `status`, `type`, |
5 | | -`title`, `detail`, etc. |
| 3 | +When you raise your own exceptions implementing `Zend\ProblemDetails\Exception\ProblemDetailsExceptionInterface` |
| 4 | +you will always be in control of all the properties returned as part of the |
| 5 | +response payload, including the `status`, `type`, `title`, `detail`, etc. |
| 6 | +items. |
6 | 7 |
|
7 | | -However, there are some use cases in which this library will have to infer some of those values. |
| 8 | +However, there are some use cases in which this library will have to infer some |
| 9 | +of those values. |
8 | 10 |
|
9 | 11 | The main situations in which this can happen are: |
10 | 12 |
|
11 | | -* When an exception not implementing `ProblemDetailsExceptionInterface` is captured by the `ProblemDetailsMiddleware`. |
12 | | -* When the `ProblemDetailsNotFoundHandler` is executed. |
| 13 | +- When an exception not implementing `ProblemDetailsExceptionInterface` is |
| 14 | + captured by the `ProblemDetailsMiddleware`. |
| 15 | +- When the `ProblemDetailsNotFoundHandler` is executed. |
13 | 16 |
|
14 | | -In these two cases, the `title` and `type` properties will be inferred from the status code, which will usually be |
15 | | -`500` in the first case and `404` in the second one. |
| 17 | +In these two cases, the `title` and `type` properties will be inferred from the |
| 18 | +status code, which will usually be `500` in the first case and `404` in the |
| 19 | +second one. |
16 | 20 |
|
17 | | -> To be more precise, the `ProblemDetailsMiddleware` will use the exception's error code when `debug` is `true`, |
18 | | -> and `500` otherwise. |
| 21 | +> To be more precise, the `ProblemDetailsMiddleware` will use the exception's |
| 22 | +> error code when `debug` is `true`, and `500` otherwise. |
19 | 23 |
|
20 | | -Because of this, in any of those cases, you will end up with values like `https://httpstatus.es/404` or |
21 | | -`https://httpstatus.es/500` for the `type` property. |
| 24 | +Because of this, in any of those cases, you will end up with values like |
| 25 | +`https://httpstatus.es/404` or `https://httpstatus.es/500` for the `type` |
| 26 | +property. |
22 | 27 |
|
23 | 28 | ## Configuring custom default types |
24 | 29 |
|
25 | | -Since the `type` property will usually be used by API consumers to uniquely identify an error, you might want to be |
26 | | -able to provide your own custom values for the `type` property. |
| 30 | +Since the `type` property will usually be used by API consumers to uniquely |
| 31 | +identify an error, you might want to be able to provide your own custom values |
| 32 | +for the `type` property. |
27 | 33 |
|
28 | | -In order to do that, this library lets you configure the default `type` value to be used for every status code |
29 | | -when some of the cases listed above happens. |
| 34 | +In order to do that, this library lets you configure the default `type` value to |
| 35 | +be used for every status code when some of the cases listed above happens. |
30 | 36 |
|
31 | 37 | ```php |
32 | 38 | return [ |
33 | | - |
34 | 39 | 'problem-details' => [ |
35 | 40 | 'default_types_map' => [ |
36 | 41 | 404 => 'https://example.com/problem-details/error/not-found', |
37 | 42 | 500 => 'https://example.com/problem-details/error/internal-server-error', |
38 | 43 | ], |
39 | 44 | ], |
40 | | - |
41 | 45 | ]; |
42 | 46 | ``` |
43 | 47 |
|
44 | 48 | If this configuration is found, it will be consumed by the |
45 | | -[ProblemDetailsResponseFactoryFactory](response.md#problemdetailsresponsefactoryfactory) and your custom values will |
46 | | -be used when the `type` was not explicitly provided. |
| 49 | +[ProblemDetailsResponseFactoryFactory](response.md#problemdetailsresponsefactoryfactory) |
| 50 | +and your custom values will be used when the `type` was not explicitly provided. |
0 commit comments