We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

set_status_header, and send_ajax_response no longer working with 422 after upgrading from 6 to 7

Development and Programming

benjivm's avatar
benjivm
5 posts
2 months ago
benjivm's avatar benjivm

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.

       
Tom Jaeger's avatar
Tom Jaeger
442 posts
2 months ago
Tom Jaeger's avatar Tom Jaeger

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

       
benjivm's avatar
benjivm
5 posts
2 months ago
benjivm's avatar benjivm

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?

       
Tom Jaeger's avatar
Tom Jaeger
442 posts
2 months ago
Tom Jaeger's avatar Tom Jaeger

For those following along. This was released as part of ExpressionEngine 7.5.16

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.