My addon has the following lines, working fine on EE 6:
$http = (new Http())
->withOptions(['base_uri' => ee('Config')->get('my_api').'/'])
->withToken(ee('Config')->get('my_token'))
->acceptJson();
$response = $http->post($endpoint, $data);
ee()->output->set_status_header($response->status(), $response->reason());
ee()->output->send_ajax_response($response->json(), $response->status());Now, if the status code is 422, I receive the following on the frontend:
{
"error": "No status text available. Please check your status code number or supply your own message text."
}Changing the status code to anything else works.
Hi Ben,
Thanks for posting this… Any chance you would be willing to try this fix
Would be awesome if you could leave a comment on the PR if it works for you as well!
Either way we’ll aim to get this out in the next release!
-Tom Jaeger
I tested the PR and it does resolve the issue, thanks.
Can you confirm that this is unnecessary:
ee()->output->set_status_header($response->status(), $response->reason());
ee()->output->send_ajax_response($response->json(), $response->status());And all I need is this:
ee()->output->send_ajax_response($response->json(), $response->status());Or what is the preferred way of sending a payload to be consumed by a javascript frontend?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.