This is another go at how responses from patch and bulk actions should be structured.
I would like those to be obvious not only for the actions running them, but also common error handling logic. Not some "if response.threads is array, then do this, but its response.threads.details, then do that" kind of stuff.
Because using status codes for error handling in bulk actions leads to great pain and code duplication in the frontend, the idea is for bulk action handlers to always return 200. That way if errors occur earlier (eg. in input sanitizer), we can return 400 or other error status code and thus hit frontend's usual error handling logic shared with non-bulk views.
Bulk action's 200 response is always list of objects, containing item's id and result code (eg. {'id': 123, status: 200}). In addition to this, object may contain additional props related to its status code. Bulk patch's item with status 200 will have patch prop with updated props to send to store. Failed item will have detail with usual error detail.
Items are sorted by id key using ascending ordering.
Example
[
{
"id": "1",
"status": "200",
"patch": {
"title": "Successfully renamed thread!"
}
},
{
"id": "2",
"status": "400",
"detail": "You have to enter thread title!"
},
{
"id": "3",
"status": "403",
"detail": "You don't have permission to edit this thread!"
},
{
"id": "4",
"status": "404",
"detail": "Requested thread doesn't exist or you don't have permission to see it!"
}
]
This is another go at how responses from patch and bulk actions should be structured.
I would like those to be obvious not only for the actions running them, but also common error handling logic. Not some "if
response.threads
is array, then do this, but itsresponse.threads.details
, then do that" kind of stuff.Because using status codes for error handling in bulk actions leads to great pain and code duplication in the frontend, the idea is for bulk action handlers to always return 200. That way if errors occur earlier (eg. in input sanitizer), we can return 400 or other error status code and thus hit frontend's usual error handling logic shared with non-bulk views.
Bulk action's 200 response is always list of objects, containing item's id and result code (eg.
{'id': 123, status: 200}
). In addition to this, object may contain additional props related to its status code. Bulk patch's item with status 200 will havepatch
prop with updated props to send to store. Failed item will havedetail
with usual error detail.Items are sorted by
id
key using ascending ordering.Example