Error: Expected reject to be called with Error, got [object Undefined]

Hi, I am currently developing a CustomUI App. It runs fine for admin users.
However, I just created a normal User without any admin permissions, and whenever I load the app, I get the prompt to “Allow access” for the App, followed by a second such prompt, and then the App never loads and this error is thrown in the Chrome console:

Error: Expected reject to be called with Error, got [object Undefined]
    at t.reject (https://jira-frontend-static.prod.public.atl-paas.net/assets-brotli/async-forge-ui-iframe-full-page.fd6977f46e491475a3b7.8.js:839:769)
    at https://jira-frontend-static.prod.public.atl-paas.net/assets-brotli/async-forge-ui-iframe-full-page.fd6977f46e491475a3b7.8.js:839:209

Error: Expected reject to be called with Error, got [object Undefined]
    at hn.error (https://forge.cdn.prod.atlassian-dev.net/global-bridge.js:1:19406)
    at Object.<anonymous> (https://forge.cdn.prod.atlassian-dev.net/global-bridge.js:1:27179)
    at JSON.parse (<anonymous>)
    at o (https://forge.cdn.prod.atlassian-dev.net/global-bridge.js:1:27038)
    at jn (https://forge.cdn.prod.atlassian-dev.net/global-bridge.js:1:27191)
    at Tn.u.on (https://forge.cdn.prod.atlassian-dev.net/global-bridge.js:1:31851)
    at Tn (https://forge.cdn.prod.atlassian-dev.net/global-bridge.js:1:31988)
    at https://forge.cdn.prod.atlassian-dev.net/global-bridge.js:1:37974
    at n.try (https://forge.cdn.prod.atlassian-dev.net/global-bridge.js:1:10458)
    at https://forge.cdn.prod.atlassian-dev.net/global-bridge.js:1:37771

I am stuck and I do not know how to debug this. The error seems to be happening at the entry point for the app, where I call the following:

const context = await view.getContext()
const history = await view.createHistory()
const myself = await invoke('getMyself')
const flows = await invoke('getFlows')
const canvas = await invoke('getCanvas')
resolver.define('getFlows', async (req) => {
    console.log('getFlows');
    const savedFlows = await storage.get('savedFlows');
    const projectFlows = Object.keys(req.payload).length ? savedFlows?.filter(flows => flows.projectKey === req.payload) : savedFlows
    return projectFlows || []
});
resolver.define('getCanvas', async (req) => {
    console.log('getCanvas');
    const canvas = await storage.get('canvas');
    return canvas || {}
});
resolver.define('getMyself', async (req) => {
    console.log('getMyself');
    const response = await api.asUser().requestJira(route`/rest/api/2/myself`)
    return response.json();
});

It looks like the issue isn’t permissions related, as I deployed the App into production, and now the Admins face this issue, while the normal user doesn’t. Any help is appreciated.

Were you able to figure this out? I went back to the hello-world app and narrowed it down to simply having “permissions > external > fetch > backend” in my manifest, even though the hello-world app has no fetch calls anywhere.

I am now also suffering from this problem, after adding a new scope (write:jira-work).

I was able to get rid of it in my dev site by:

  1. Commenting out the new scope. This also required commenting out the REST API call that uses it.
  2. Redeploying to dev. No reinstall.
  3. Forge tunnel.
  4. Refresh browser page. The app works again.
  5. Re-add scope. Redeploy. Refresh page. Accept permissions.
  6. Re-add code that uses the scope. Redeploy. Refresh page. Still working.

I think that there may be a long-standing bug that strikes when adding a scope to an existing app that is already installed.

There are back-end logs that say:

[NEEDS_AUTHENTICATION_ERR: Authentication Required] { status: 401, serviceKey: ‘atlassian-token-service-key’, options: undefined }

My app does not use any custom UI.