Skip to content

Plugin Class does not exists

I am creating plugin to alter API response in M2.4.3. I am trying to alter this functionality via plugin
MagentoFrameworkWebapiRestResponse and function prepareResponse
My di.xml file is:

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoFrameworkWebapiRestResponse">
        <plugin name="vendor_apiresponses_extend_Webapi_rest_response" type="VendorApiResponsesPluginFrameworkWebapiRestResponseUpdateResponse" />
    </type>
</config>

and plugin file is :

<?php

declare(strict_types=1);

namespace VendorApiResponsesPluginFrameworkWebapiRestResponse;

use MagentoFrameworkWebapiRestResponse;

class UpdateResponse
{

    /**
     * @param Response $subject
     * @param $outputData
     * @return array
     */
    public function beforePrepareResponse(
        Response $subject,
        $outputData = null
    ): array
    {
        $newResponseStructure['body'] = $outputData;
        return $newResponseStructure;
    }
}

on calling I am facing following error:

Error: Class 'VendorApiResponsesPluginFrameworkWebapiRestResponseUpdateResponse' not found in /var/www/html/vendor/magento/framework/ObjectManager/Factory/Compiled.php:60
Stack trace:
#0 /var/www/html/vendor/magento/framework/ObjectManager/ObjectManager.php(70): MagentoFrameworkObjectManagerFactoryCompiled->create('Vendor\ApiResp...')
#1 /var/www/html/vendor/magento/framework/Interception/PluginList/PluginList.php(174): MagentoFrameworkObjectManagerObjectManager->get('Vendor\ApiResp...')
#2 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(119): MagentoFrameworkInterceptionPluginListPluginList->getPlugin('Magento\Framewo...', 'vendor_apiresp...')
#3 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): MagentoFrameworkWebapiRestResponseInterceptor->MagentoFrameworkInterception{closure}(Array)
#4 /var/www/html/generated/code/Magento/Framework/Webapi/Rest/Response/Interceptor.php(23): MagentoFrameworkWebapiRestResponseInterceptor->___callPlugins('prepareResponse', Array, Array)
#5 /var/www/html/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php(108): MagentoFrameworkWebapiRestResponseInterceptor->prepareResponse(Array)
#6 /var/www/html/vendor/magento/module-webapi/Controller/Rest.php(188): MagentoWebapiControllerRestSynchronousRequestProcessor->process(Object(MagentoFrameworkWebapiRestRequestProxy))
#7 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): MagentoWebapiControllerRest->dispatch(Object(MagentoFrameworkAppRequestHttp))
#8 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): MagentoWebapiControllerRestInterceptor->___callParent('dispatch', Array)
#9 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): MagentoWebapiControllerRestInterceptor->MagentoFrameworkInterception{closure}(Object(MagentoFrameworkAppRequestHttp))
#10 /var/www/html/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(23): MagentoWebapiControllerRestInterceptor->___callPlugins('dispatch', Array, Array)
#11 /var/www/html/vendor/magento/framework/App/Http.php(116): MagentoWebapiControllerRestInterceptor->dispatch(Object(MagentoFrameworkAppRequestHttp))
#12 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): MagentoFrameworkAppHttp->launch()
#13 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): MagentoFrameworkAppHttpInterceptor->___callParent('launch', Array)
#14 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): MagentoFrameworkAppHttpInterceptor->MagentoFrameworkInterception{closure}()
#15 /var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php(23): MagentoFrameworkAppHttpInterceptor->___callPlugins('launch', Array, Array)
#16 /var/www/html/vendor/magento/framework/App/Bootstrap.php(264): MagentoFrameworkAppHttpInterceptor->launch()
#17 /var/www/html/pub/index.php(29): MagentoFrameworkAppBootstrap->run(Object(MagentoFrameworkAppHttpInterceptor))
#18 {main}

What is missing in above ?