SAP / ui5-tooling

An open and modular toolchain to develop state of the art applications based on the UI5 framework
https://sap.github.io/ui5-tooling
Apache License 2.0
469 stars 71 forks source link

[fiori-tools-proxy] Cannot read properties of undefined (reading 'status') when working behind corporate network with proxy #684

Closed michaelnny closed 2 years ago

michaelnny commented 2 years ago

When using the UI5 tooling package in a corporate network environment which require proxy to access internet, the tool failed to run any UI5 project, as there seems to be a bug inside the function 'isUI5VersionRemoved' in the module 'fiori-tools-proxy'. The root cause seems to be that the axios client call didn't using the proxy configuration from the system, thus the call will fail without any response status code.

async function isUI5VersionRemoved(ui5Version) {
  if (ui5Version && !isNaN(parseFloat(ui5Version))) {
    try {
      const response = await import_axios.default.get(`${import_ux_ui5_info.UI5Info.OfficialUrl}/${ui5Version}/resources/sap-ui-core.js`);
      return response.status === 404;
    } catch (err) {
      // BUG - If Axios call failed, the err.response is undefined.
      return err.response.status === 404;
    }
  }
  return false;
}

Currently the workaround would be to either switching to "@sap/ux-ui5-tooling" release "1.7.0", or manually modify the code in module '@sap\ux-ui5-tooling\dist\middlewares\fiori-tools-proxy.js':

async function isUI5VersionRemoved(ui5Version) {
  if (ui5Version && !isNaN(parseFloat(ui5Version))) {
    try {
      const response = await import_axios.default.get(`${import_ux_ui5_info.UI5Info.OfficialUrl}/${ui5Version}/resources/sap-ui-core.js`);
      return response.status === 404;
    } catch (err) {
      if (err.response && 'status' in err.response) {
        return err.response.status === 404;
      }
      return false;
    }
  }
  return false;
}

Expected Behavior

When using command 'npm run start' should be able to start and run the UI5 project.

Current Behavior

When using command 'npm run start', we get the error from console:

Error Message: Cannot read properties of undefined (reading 'status')

Steps to Reproduce the Issue

  1. Generate a new UI5 project, either freestyle or Fiori elements will be able to reproduce the issue
  2. Run 'npm run start' to start the project

Context

Log Output / Stack Trace

Stack Trace:
TypeError: Cannot read properties of undefined (reading 'status')
    at isUI5VersionRemoved (C:\Users\XXXXX\projects\test_project1\node_modules\@sap\ux-ui5-tooling\dist\middlewares\fiori-tools-proxy.js:110445:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)   
    at async getUI5Config (C:\Users\XXXXX\projects\test_project1\node_modules\@sap\ux-ui5-tooling\dist\middlewares\fiori-tools-proxy.js:110659:9)
    at async module.exports (C:\Users\XXXXX\projects\test_project1\node_modules\@sap\ux-ui5-tooling\dist\middlewares\fiori-tools-proxy.js:110713:50)
    at async MiddlewareManager.addMiddleware (C:\Users\XXXXX\projects\test_project1\node_modules\@ui5\cli\node_modules\@ui5\server\lib\middleware\MiddlewareManager.js:89:16)
    at async MiddlewareManager.addCustomMiddleware (C:\Users\XXXXX\projects\test_project1\node_modules\@ui5\cli\node_modules\@ui5\server\lib\middleware\MiddlewareManager.js:237:4)
    at async MiddlewareManager.applyMiddleware (C:\Users\XXXXX\projects\test_project1\node_modules\@ui5\cli\node_modules\@ui5\server\lib\middleware\MiddlewareManager.js:38:3)
    at async Object.serve (C:\Users\XXXXX\projects\test_project1\node_modules\@ui5\cli\node_modules\@ui5\server\lib\server.js:166:3)
    at async serve.handler (C:\Users\XXXXX\projects\test_project1\node_modules\@ui5\cli\lib\cli\commands\serve.js:130:33)
matz3 commented 2 years ago

fiori-tools-proxy is part of the @sap/ux-ui5-tooling module. The SAP Fiori Tools project is not part of the UI5 Tooling project (our modules all start with @ui5/*).

You can get in touch with the SAP Fiori tools team via the SAP Community Website: https://community.sap.com/topics/fiori-tools

You can also find related documentation here: https://help.sap.com/viewer/product/SAP_FIORI_tools/Latest/en-US