jsmrtn / craftagram

Grab Instagram content through the Instagram Basic Display API
Other
14 stars 8 forks source link

Headless endpoint error #37

Closed chrishale closed 3 years ago

chrishale commented 3 years ago

I'm finding when fetching the headless endpoint at /actions/craftagram/default/api my JSON parse fails.

Perhaps because I'm in development mode, but I'm seeing the following error returned alongside the JSON:

<pre>An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in /var/www/craft/vendor/scaramangagency/craftagram/src/controllers/DefaultController.php on line 106. in /var/www/craft/vendor/yiisoft/yii2/web/Response.php:366
Stack trace:
#0 /var/www/craft/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response-&gt;sendHeaders()
#1 /var/www/craft/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response-&gt;send()
#2 /var/www/craft/vendor/craftcms/cms/src/web/ErrorHandler.php(147): yii\web\ErrorHandler-&gt;renderException()
#3 /var/www/craft/vendor/yiisoft/yii2/base/ErrorHandler.php(135): craft\web\ErrorHandler-&gt;renderException()
#4 /var/www/craft/vendor/craftcms/cms/src/web/ErrorHandler.php(63): yii\base\ErrorHandler-&gt;handleException()
#5 [internal function]: craft\web\ErrorHandler-&gt;handleException()
#6 {main}
Previous exception:
yii\web\NotFoundHttpException: Page not found. in /var/www/craft/vendor/craftcms/cms/src/web/Request.php:1250
Stack trace:
#0 /var/www/craft/vendor/yiisoft/yii2/web/Application.php(82): craft\web\Request-&gt;resolve()
#1 /var/www/craft/vendor/craftcms/cms/src/web/Application.php(259): yii\web\Application-&gt;handleRequest()
#2 /var/www/craft/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application-&gt;handleRequest()
#3 /var/www/craft/web/index.php(22): yii\base\Application-&gt;run()
#4 {main}</pre>

Looking at the DefaultController, I think this to be because there is no return or die() in the API action. So it goes on to look for a template to render.

chrishale commented 3 years ago

Apologies, I should have spent more time testing this. I've made another revision

jsmrtn commented 3 years ago

Thanks @chrishale. This has prompted something else that I should really address, which is that this endpoint doesn't allow anonymous requests so you need to be logged into the CMS to actually use it (which is no good as you might be requesting it from your app). I'll not merge in this PR–as I will fix this along with fixing the authentication concern, too.

jsmrtn commented 3 years ago

@chrishale This is now fixed in 1.4.4.