la-haute-societe / craft-elasticsearch

Bring the power of Elasticsearch to your Craft CMS projects
Other
18 stars 14 forks source link

How to use this on Headless configuration #13

Closed odelonmiranda closed 4 years ago

odelonmiranda commented 4 years ago

We are using a headless implementation of CraftCMS Encountering 404 error.

GET http://craftcms.local/collection-page?token=lKeov1GrWq1QHGqwXXgu3UGSuhifdAx8` resulted in a `404 Not Found` response:
{"name":"Not Found","message":"Page not found.","code":0,"status":404,"type":"yii\\web\\NotFoundHttpException"}

But since we are using headless we don't have any template

maximilian-schwarz commented 4 years ago

Hello,

you need to write a custom contentextractorcallback: https://github.com/la-haute-societe/craft-elasticsearch#contentextractorcallback

Because the default contentextractorcallback function crawl the html content from the page via guzzle.

dstrunk commented 3 years ago

Hey there, I hope I'm not resurrecting this issue unnecessarily, but I don't think this can be resolved by writing a custom contentextractorcallback (by itself). It looks like Guzzle throws exceptions on 404 status codes by default, which is getting swallowed by the try/catch in la-haute-societe/craft-elasticsearch/src/services/ElementIndexerService.php:248.

In Guzzle, it looks like it's possible to turn off exceptions for 400/500 statuses: https://docs.guzzlephp.org/en/stable/request-options.html#http-errors … it seems like this (handled in la-haute-societe/craft-elasticsearch/src/services/ElementIndexerService.php:241), coupled with testing for headless mode is necessary before we can adjust the contentextractorcallback method in the config.

I'm going to see if I can submit a PR on this in the next week or so if somebody isn't able to look into this before then.