8000 Merge branch 'release/3.1.0' · CodingSeo/laravel-json-api@94757b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94757b6

Browse files
committed
Merge branch 'release/3.1.0'
2 parents 11a8efd + dcf9f8f commit 94757b6

File tree

9 files changed

+410
-19
lines changed

9 files changed

+410
-19
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
All notable changes to this project will be documented in this file. This project adheres to
33
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
44

5+
## [3.1.0] - 2020-10-28
6+
7+
### Added
8+
- [#563](https://github.com/cloudcreativity/laravel-json-api/pull/563)
9+
Added Dutch translation files for validation and errors.
10+
11+
### Fixed
12+
- [#566](https://github.com/cloudcreativity/laravel-json-api/issues/566)
13+
Ensure the exception parser correctly parses an instance of this package's `JsonApiException`.
14+
- Exception parser now correctly uses the Symfony `HttpExceptionInterface` instead of the
15+
actual `HttpException` instance. Although this change would break consuming applications
16+
that have extended the `ExceptionParser` class, it is considered a bug fix as it should
17+
have been type-hinting the interface in `v3.0.0`.
18+
519
## [3.0.1] - 2020-10-14
620

721
### Fixed

resources/lang/en/errors.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454

5555
'member_required' => [
5656
'title' => 'Non-Compliant JSON API Document',
57-
'detail' => "The member :member is required.",
57+
'detail' => 'The member :member is required.',
5858
'code' => '',
5959
],
6060

6161
'member_object_expected' => [
6262
'title' => 'Non-Compliant JSON API Document',
63-
'detail' => "The member :member must be an object.",
63+
'detail' => 'The member :member must be an object.',
6464
'code' => '',
6565
],
6666

@@ -72,37 +72,37 @@
7272

7373
'member_string_expected' => [
7474
'title' => 'Non-Compliant JSON API Document',
75-
'detail' => "The member :member must be a string.",
75+
'detail' => 'The member :member must be a string.',
7676
'code' => '',
7777
],
7878

7979
'member_empty' => [
8080
'title' => 'Non-Compliant JSON API Document',
81-
'detail' => "The member :member cannot be empty.",
81+
'detail' => 'The member :member cannot be empty.',
8282
'code' => '',
8383
],
8484

8585
'member_field_not_allowed' => [
8686
'title' => 'Non-Compliant JSON API Document',
87-
'detail' => "The member :member cannot have a :field field.",
87+
'detail' => 'The member :member cannot have a :field field.',
8888
'code' => '',
8989
],
9090

9191
'resource_type_not_supported' => [
9292
'title' => 'Not Supported',
93-
'detail' => "Resource type :type is not supported by this endpoint.",
93+
'detail' => 'Resource type :type is not supported by this endpoint.',
9494
'code' => '',
9595
],
9696

9797
'resource_type_not_recognised' => [
9898
'title' => 'Not Supported',
99-
'detail' => "Resource type :type is not recognised.",
99+
'detail' => 'Resource type :type is not recognised.',
100100
'code' => '',
101101
],
102102

103103
'resource_id_not_supported' => [
104104
'title' => 'Not Supported',
105-
'detail' => "Resource id :id is not supported by this endpoint.",
105+
'detail' => 'Resource id :id is not supported by this endpoint.',
106106
'code' => '',
107107
],
108108

@@ -114,13 +114,13 @@
114114

115115
'resource_exists' => [
116116
'title' => 'Conflict',
117-
'detail' => "Resource :id already exists.",
117+
'detail' => 'Resource :id already exists.',
118118
'code' => '',
119119
],
120120

121121
'resource_not_found' => [
122122
'title' => 'Not Found',
123-
'detail' => "The related resource does not exist.",
123+
'detail' => 'The related resource does not exist.',
124124
'code' => '',
125125
],
126126

resources/lang/nl/errors.php

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
/**
3+
* Copyright 2020 Cloud Creativity Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
return [
19+
20+
/*
21+
|--------------------------------------------------------------------------
22+
| Error Object Language Lines
23+
|--------------------------------------------------------------------------
24+
|
25+
| The following language lines contain the default translatable members
26+
| of JSON API error objects. According to the JSON API spec, the
27+
| `title` and `detail` members can be localized. In addition the `code`
28+
| member is also read from this package if you want to give the error
29+
| a specific code.
30+
|
31+
| Set any value to an empty string if you do not want the member to be
32+
| included in the error object.
33+
|
34+
| @see http://jsonapi.org/format/#errors
35+
*/
36+
37+
'unauthorized' => [
38+
'title' => 'Ongeauthenticeerd',
39+
'detail' => '',
40+
'code' => '',
41+
],
42+
43+
'forbidden' => [
44+
'title' => 'Ongeautoriseerd',
45+
'detail' => '',
46+
'code' => '',
47+
],
48+
49+
'token_mismatch' => [
50+
'title' => 'Ongeldig Token',
51+
'detail' => 'Het token is niet geldig.',
52+
'code' => '',
53+
],
54+
55+
'member_required' => [
56+
'title' => 'Niet-Conform JSON API Document',
57+
'detail' => 'Het onderdeel :member is vereist.',
58+
'code' => '',
59+
],
60+
61+
'member_object_expected' => [
62+
'title' => 'Niet-Conform JSON API Document',
63+
'detail' => 'Het onderdeel :member moet een object zijn.',
64+
'code' => '',
65+
],
66+
67+
'member_identifier_expected' => [
68+
'title' => 'Niet-Conform JSON API Document',
69+
'detail' => 'Het onderdeel :member moet een resource identifier zijn.',
70+
'code' => '',
71+
],
72+
73+
'member_string_expected' => [
74+
'title' => 'Niet-Conform JSON API Document',
75+
'detail' => 'Het onderdeel :member moet een string zijn.',
76+
'code' => '',
77+
],
78+
79+
'member_empty' => [
80+
'title' => 'Niet-Conform JSON API Document',
81+
'detail' => 'Het onderdeel :member kan niet leeg zijn.',
82+
'code' => '',
83+
],
84+
85+
'member_field_not_allowed' => [
86+
'title' => 'Niet-Conform JSON API Document',
87+
'detail' => 'Het onderdeel :member kan niet een veld :field hebben.',
88+
'code' => '',
89+
],
90+
91+
'resource_type_not_supported' => [
92+
'title' => 'Niet Ondersteund',
93+
'detail' => 'Resource type :type wordt niet ondersteund door dit endpoint.',
94+
'code' => '',
95+
],
96+
97+
'resource_type_not_recognised' => [
98+
'title' => 'Niet Ondersteund',
99+
'detail' => 'Resource type :type wordt niet herkend.',
100+
'code' => '',
101+
],
102+
103+
'resource_id_not_supported' => [
104+
'title' => 'Niet Ondersteund',
105+
'detail' => 'Resource id :id wordt niet ondersteund door dit endpoint.',
106+
'code' => '',
107+
],
108+
109+
'resource_client_ids_not_supported' => [
110+
'title' => 'Niet Ondersteund',
111+
'detail' => 'Resource type :type ondersteunt geen client-gegenereerde IDs.',
112+
'code' => '',
113+
],
114+
115+
'resource_exists' => [
116+
'title' => 'Conflict',
117+
'detail' => 'Resource :id bestaat al.',
118+
'code' => '',
119+
],
120+
121+
'resource_not_found' => [
122+
'title' => 'Niet gevonden',
123+
'detail' => 'De gerelateerde resource bestaat niet.',
124+
'code' => '',
125+
],
126+
127+
'resource_field_exists_in_attributes_and_relationships' => [
128+
'title' => 'Niet-Conform JSON API Document',
129+
'detail' => 'Het veld :field kan niet bestaan als een attribuut en een relatie.',
130+
'code' => '',
131+
],
132+
133+
'resource_invalid' => [
134+
'title' => 'Onverwerkbare Entiteit',
135+
'detail' => 'Het document was goed opgemaakt, maar bevat semantische fouten.',
136+
'code' => '',
137+
],
138+
139+
'resource_cannot_be_deleted' => [
140+
'title' => 'Niet Verwijderbaar',
141+
'detail' => 'Deze resource kan niet worden verwijderd.',
142+
'code' => '',
143+
],
144+
145+
'query_invalid' => [
146+
'title' => 'Ongeldige queryparameter',
147+
'detail' => 'De queryparameters van het verzoek zijn ongeldig.',
148+
'code' => '',
149+
],
150+
151+
'failed_validator' => [
152+
'title' => 'Onverwerkbare Entiteit',
153+
'detail' => 'Het document was goed opgemaakt, maar bevat semantische fouten.',
154+
'code' => '',
155+
],
156+
];

resources/lang/nl/validation.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright 2020 Cloud Creativity Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
return [
19+
20+
/*
21+
|--------------------------------------------------------------------------
22+
| Validation Language Lines
23+
|--------------------------------------------------------------------------
24+
|
25+
| The following language lines contain the default error messages used by
26+
| the validation rules for this package.
27+
|
28+
*/
29+
30+
'allowed_field_sets' => [
31+
'default' => 'Spaarzame veldsets mogen alleen toegestane bevatten.',
32+
'singular' => 'Spaarzame veldset :values is niet toegestaan.',
33+
'plural' => 'Spaarzame veldsets :values zijn niet toegestaan.',
34+
],
35+
36+
'allowed_filter_parameters' => [
37+
'default' => 'Filterparameters mogen alleen toegestane bevatten.',
38+
'singular' => 'Filterparameter :values is niet toegestaan.',
39+
'plural' => 'Filterparameters :values zijn niet toegestaan.',
40+
],
41+
42+
'allowed_include_paths' => [
43+
'default' => 'Insluit-paden mogen alleen toegestane bevatten.',
44+
'singular' => 'Insluit-pad :values is niet toegestaan.',
45+
'plural' => 'Insluit-paden :values zijn niet toegestaan.',
46+
],
47+
48+
'allowed_sort_parameters' => [
49+
'default' => 'Sorteerparameters mogen alleen toegestane bevatten.',
50+
'singular' => 'Sorteerparameter :values is niet toegestaan.',
51+
'plural' => 'Sorteerparameters :values zijn niet toegestaan.',
52+
],
53+
54+
'allowed_page_parameters' => [
55+
'default' => 'Pagina-parameters mogen alleen toegestane bevatten.',
56+
'singular' => 'Pagina-parameter :values is niet toegestaan.',
57+
'plural' => 'Pagina-parameters :values zijn niet toegestaan.',
58+
],
59+
60+
'date_time_iso_8601' => 'Het attribuut :attribute heeft geen geldig ISO 8601 datum/tijd formaat.',
61+
62+
'disallowed_parameter' => 'Parameter :name is niet toegestaan.',
63+
64+
'has_one' => 'Het veld :attribute moet een naar-één relatie zijn die :types resources bevat.',
65+
66+
'has_many' => 'Het veld :attribute moet een naar-velen relatie zijn die :types resources bevat.',
67+
];

src/Exceptions/ExceptionParser.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@
2121
use CloudCreativity\LaravelJsonApi\Contracts\Exceptions\ExceptionParserInterface;
2222
use CloudCreativity\LaravelJsonApi\Document\Error\Translator;
2323
use CloudCreativity\LaravelJsonApi\Encoder\Neomerx\Document\Errors as NeomerxErrors;
24-
use Exception;
2524
use Illuminate\Auth\Access\AuthorizationException;
2625
use Illuminate\Auth\AuthenticationException;
2726
use Illuminate\Http\Response;
2827
use Illuminate\Session\TokenMismatchException;
2928
use Illuminate\Validation\ValidationException as IlluminateValidationException;
3029
use Neomerx\JsonApi\Contracts\Document\ErrorInterface;
3130
use Neomerx\JsonApi\Document\Error;
32-
use Neomerx\JsonApi\Exceptions\JsonApiException;
33-
use Symfony\Component\HttpKernel\Exception\HttpException;
31+
use Neomerx\JsonApi\Exceptions\JsonApiException as NeomerxJsonApiException;
3432
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
3533

3634
/**
@@ -62,6 +60,10 @@ public function __construct(Translator $translator)
6260
public function parse(\Throwable $e): DocumentInterface
6361
{
6462
if ($e instanceof JsonApiException) {
63+
return $e->getErrors();
64+
}
65+
66+
if ($e instanceof NeomerxJsonApiException) {
6567
return NeomerxErrors::cast($e);
6668
}
6769

@@ -95,7 +97,7 @@ protected function getErrors(\Throwable $e): array
9597
return [$this->translator->tokenMismatch()];
9698
}
9799

98-
if ($e instanceof HttpException) {
100+
if ($e instanceof HttpExceptionInterface) {
99101
return [$this->getHttpError($e)];
100102
}
101103

@@ -112,10 +114,10 @@ protected function getValidationError(IlluminateValidationException $e): array
112114
}
113115

114116
/**
115-
* @param HttpException $e
117+
* @param HttpExceptionInterface $e
116118
* @return ErrorInterface
117119
*/
118-
protected function getHttpError(HttpException $e): ErrorInterface
120+
protected function getHttpError(HttpExceptionInterface $e): ErrorInterface
119121
{
120122
$status = $e->getStatusCode();
121123
$title = $this->getDefaultTitle($status);

src/Exceptions/JsonApiException.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,22 @@ public function getHeaders()
9292
return $this->headers;
9393
}
9494

95+
/**
96+
* @return Errors
97+
*/
98+
public function getErrors(): Errors
99+
{
100+
return $this->errors
101+
->withHeaders($this->headers);
102+
}
103+
95104
/**
96105
* @inheritDoc
97106
*/
98107
public function toResponse($request)
99108
{
100-
return $this->errors
101-
->withHeaders($this->headers)
109+
return $this
110+
->getErrors()
102111
->toResponse($request);
103112
}
104113

0 commit comments

Comments
 (0)
0