I want to return a custom HTTP status code in a PHP serverless function. But the following code:
return ['body' => ['test'=>'Lorem ipsum'], 'statusCode' => 404];
Has this output (with HTTP status 200):
{"body":{"test":"Lorem ipsum"},"statusCode":404}
Expected output (with HTTP status 404):
{"test":"Lorem ipsum"}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
hello @accountmorel
Here is a minimal example that the function returns an error repose along with an HTTP status code and additional HTTP headers:
You can find more information here:
https://www.digitalocean.com/community/tags/serverless
https://php.watch/articles/php-serverless-digital-ocean
Hope that this helps!