Magento – Magento 2: Running any command getting error Class Magento\Webapi\Model\Cache\Type\Web Api\Interceptor does not exist
commanderrormagento2server-setupwebapi
Running any command
s:up , s:di:cs:s:d -fcache getting error
Class Magento\Webapi\Model\Cache\Type\WebApi\Interceptor does not
exist
And like below images, any help will be appreciate.
Best Answer
Please, check that interceptor class on your server:
ls -la generated/code/Magento/Webapi/Model/Cache/Type/Webapi/Interceptor.php
(from Magento root dir.)
In case it has a wrong permissions change it according your needs (usually make it accessible by web-server user is enough).
Another case that interceptor class used somewhere in your code directly (or in third-party extensions) but it must not be used directly. Use grep on your code directory to check it.
Another case is when file totally missed from the Magento (missed base class Magento\Webapi\Model\Cache\Type\WebApi). In that case I'll recommend you to update Magento using composer.
I finally manage to resolve this issue.
After digging into the Magento core, I found that in the \Magento\Framework\Reflection\ExtensionAttributeProcessor::buildOutputDataArray method, Magento get the type of the extension object attribute (in my case : Vendor\MultipleDiscounts\Api\Data\DiscountOrderItemInterface[]). If type is array, then Magento will substring the [] characters.
In my case the type was wrong : object Collection.
I use an observer to set my extension_attribute (sales order load after) and I have to change my code like this :
Best Answer
Please, check that interceptor class on your server:
(from Magento root dir.)
In case it has a wrong permissions change it according your needs (usually make it accessible by web-server user is enough).
Another case that interceptor class used somewhere in your code directly (or in third-party extensions) but it must not be used directly. Use
grep
on your code directory to check it.Another case is when file totally missed from the Magento (missed base class
Magento\Webapi\Model\Cache\Type\WebApi
). In that case I'll recommend you to update Magento using composer.