Skip to content

Commit f3f99cb

Browse files
committed
docs: fix example in ResponseTrait::fail()
1 parent cd92eab commit f3f99cb

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

system/API/ResponseTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function respond($data = null, ?int $status = null, string $message =
122122
/**
123123
* Used for generic failures that no custom methods exist for.
124124
*
125-
* @param list<string>|string $messages
125+
* @param array<array-key, string>|string $messages
126126
* @param int $status HTTP status code
127127
* @param string|null $code Custom, API-specific, error code
128128
*
@@ -230,7 +230,7 @@ protected function failNotFound(string $description = 'Not Found', ?string $code
230230
/**
231231
* Used when the data provided by the client cannot be validated on one or more fields.
232232
*
233-
* @param list<string>|string $errors
233+
* @param array<array-key, string>|string $errors
234234
*
235235
* @return ResponseInterface
236236
*/

user_guide_src/source/outgoing/api_responses.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,12 @@ Class Reference
116116
response status. Not every client will respect the custom codes, though, and will use the IANA standards
117117
that match the status code.
118118

119-
The response is an array with two elements: ``error`` and ``messages``. The ``error`` element contains the status
120-
code of the error. The ``messages`` element contains an array of error messages. It would look something like:
119+
The response is an array with three elements: ``status``, ``code``, and ``messages``.
120+
- The ``status`` element contains the status code of the error.
121+
- The ``code`` element contains a custom, API-specific error code.
122+
- The ``messages`` element contains an array of error messages.
123+
124+
Depending on the number of error messages, the response would look something like:
121125

122126
.. literalinclude:: api_responses/006.php
123127

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
<?php
22

3+
// Example response with a single error message
4+
$response = [
5+
'status' => 400,
6+
'code' => '321',
7+
'messages' => [
8+
'error' => 'An error occurred',
9+
],
10+
];
11+
12+
// Example response with multiple error messages per field
313
$response = [
414
'status' => 400,
515
'code' => '321a',
616
'messages' => [
7-
'Error message 1',
8-
'Error message 2',
17+
'foo' => 'Error message 1',
18+
'bar' => 'Error message 2',
919
],
1020
];

0 commit comments

Comments
 (0)