@@ -55,11 +55,16 @@ response
5555* [ with item] ( #with-item )
5656* [ with collection] ( #with-collection )
5757* [ error] ( #error )
58+ * [ with-error] ( #with-error )
5859 * [ 403 Forbidden] ( #403-forbidden )
5960 * [ 500 Internal Server Error] ( #500-internal-server-error )
6061 * [ 404 Not Found] ( #404-not-found )
6162 * [ 401 Unauthorized] ( #401-unauthorized )
6263 * [ 400 Bad Request] ( #400-bad-request )
64+ * [ 410 Gone] ( #410-gone )
65+ * [ 405 Method Not Allowed] ( #405-method-not-allowed )
66+ * [ 431 Request Header Fields Too Large] ( #431-request-header-fields-too-large )
67+ * [ 422 Unprocessable Entity] ( #422-unprocessable-entity )
6368
6469##### With Array
6570``` php
@@ -88,10 +93,10 @@ use PhpRestfulApiResponse\Tests\unit\Lib\Book;
8893echo $response->withItem(
8994 new Book('harry', 'harryosmarsitohang@gmail.com', 'how to be a ninja', 100000, 2017),
9095 new \PhpRestfulApiResponse\Tests\unit\Lib\Transformer\Book,
91- 200 //response code 200
96+ 201 //response code 200
9297);
9398```
94- response
99+ response 201
95100``` json
96101{
97102 "data" :
@@ -124,7 +129,7 @@ $response->withCollection(
124129 200
125130);
126131```
127- response
132+ response 200
128133``` json
129134{
130135 "data" : [
@@ -163,13 +168,26 @@ response
163168
164169#### Error
165170
171+ ##### With Error
172+ ``` php
173+ <?php
174+ /** @var \PhpRestfulApiResponse\Response $response */
175+ echo $response->withError(['error' => 'something is wrong, please try again'], 500);
176+ ```
177+ response 500
178+ ``` json
179+ {
180+ "error" : " something is wrong, please try again"
181+ }
182+ ```
183+
166184##### 403 Forbidden
167185``` php
168186<?php
169187/** @var \PhpRestfulApiResponse\Response $response */
170188echo $response->errorNotFound();
171189```
172- response
190+ response 403
173191``` json
174192{
175193 "error" :
@@ -186,7 +204,7 @@ response
186204/** @var \PhpRestfulApiResponse\Response $response */
187205echo $response->errorInternalError();
188206```
189- response
207+ response 500
190208``` json
191209{
192210 "error" :
@@ -203,7 +221,7 @@ response
203221/** @var \PhpRestfulApiResponse\Response $response */
204222echo $response->errorNotFound();
205223```
206- response
224+ response 404
207225``` json
208226{
209227 "error" :
@@ -220,7 +238,7 @@ response
220238/** @var \PhpRestfulApiResponse\Response $response */
221239echo $response->errorUnauthorized();
222240```
223- response
241+ response 401
224242``` json
225243{
226244 "error" :
@@ -240,7 +258,7 @@ echo $response->errorWrongArgs([
240258 'password' => 'required'
241259]);
242260```
243- response
261+ response 400
244262``` json
245263{
246264 "error" :
@@ -262,24 +280,7 @@ response
262280/** @var \PhpRestfulApiResponse\Response $response */
263281echo $response->errorGone();
264282```
265- response
266- ``` json
267- {
268- "error" :
269- {
270- "http_code" : 410 ,
271- "phrase" : " Unauthorized"
272- }
273- }
274- ```
275-
276- ##### 410 Gone
277- ``` php
278- <?php
279- /** @var \PhpRestfulApiResponse\Response $response */
280- echo $response->errorGone();
281- ```
282- response
283+ response 410
283284``` json
284285{
285286 "error" :
@@ -296,7 +297,7 @@ response
296297/** @var \PhpRestfulApiResponse\Response $response */
297298echo $response->errorMethodNotAllowed();
298299```
299- response
300+ response 405
300301``` json
301302{
302303 "error" :
@@ -313,7 +314,7 @@ response
313314/** @var \PhpRestfulApiResponse\Response $response */
314315echo $response->errorUnwillingToProcess();
315316```
316- response
317+ response 431
317318``` json
318319{
319320 "error" :
@@ -330,7 +331,7 @@ response
330331/** @var \PhpRestfulApiResponse\Response $response */
331332echo $response->errorUnprocessable();
332333```
333- response
334+ response 422
334335``` json
335336{
336337 "error" :
0 commit comments