Skip to Content
Aug 06, 2020 at 09:29 AM

Custom event handler for UPDATE operation fails in the handling after an "npm ci"

395 Views Last edit Aug 06, 2020 at 01:04 PM 5 rev


we are experiencing an issue related to the update operation over our entities, handled by a node.js module. In the deployment environment our script performs "npm ci" before running the module, installing the required dependencies according to the package-lock.json file. We defined a set of custom event handlers for each of the crud operations on our entities so that every CRUD request is forwarded to an external service. Since the forwarding of the token was not supported (maybe it is now) we created a custom library that dispatches the request to the right endpoint of this external service for each of the operations. While everything works when the app is run through an "npm install", that is not the case after an "npm ci". In fact, while the READ, CREATE and DELETE operations work, the UPDATE one does not despite of the fact that the logic of handling of it in our library is exactly the same. What we get is an error:

TypeError: Cannot read property 'schema' of undefined
    at <src>/srv/node_modules/@sap/cds-runtime/lib/cds-hana/client/Client.js:93:31
    at new Promise (<anonymous>)
    at Client.connect (<src>/srv/node_modules/@sap/cds-runtime/lib/cds-hana/client/Client.js:66:12)
    at SQLDatabase._testConnection (<src>/srv/node_modules/@sap/cds-runtime/lib/cds-services/connect/Service.js:314:18)
    at SQLDatabase._getAndCheckCredentials (<src>/srv/node_modules/@sap/cds-runtime/lib/cds-services/connect/Service.js:296:17)
    at SQLDatabase._createPool (<src>/srv/node_modules/@sap/cds-runtime/lib/cds-services/connect/Service.js:243:24)
    at SQLDatabase.acquire (<src>/srv/node_modules/@sap/cds-runtime/lib/cds-services/connect/Service.js:149:49)
    at _run (<src>/srv/node_modules/@sap/cds-runtime/lib/cds-services/connect/Transaction.js:57:29)
    at (<src>/srv/node_modules/@sap/cds-runtime/lib/cds-services/connect/Transaction.js:21:12)
    at (<src>/srv/node_modules/@sap/cds-runtime/lib/cds-services/services/Service.js:972:17)

This happens if it tries to connect to the database. It is ok if it cannot do that in our scenarios and we will probably need to configure our business app, but it should not attempt to do it. After this error is thrown, the custom event handler is called and the processing halts in the step of performing the actual connection with the backend service through axios, the library we use to send requests. There is a catch block for every exception we get axios related and in this case the error is not handled. In fact, when it halts, the service falls and crashes. Any idea how to fix this?