diff --git a/src/utils/entraApp.spec.ts b/src/utils/entraApp.spec.ts index 49600f89906..ccab2cca980 100644 --- a/src/utils/entraApp.spec.ts +++ b/src/utils/entraApp.spec.ts @@ -91,6 +91,14 @@ describe('utils/entraApp', () => { assert.deepStrictEqual(actual.displayName, appName); }); + it('throws error message when no application was found using getAppRegistrationByObjectId', async () => { + const error = { response: { status: 404 } }; + sinon.stub(request, 'get').rejects(error); + + await assert.rejects(entraApp.getAppRegistrationByObjectId(appObjectId), + new Error(`App with objectId '${appObjectId}' not found in Microsoft Entra ID.`)); + }); + it('handles selecting single application when multiple applications with the specified name found using getAppRegistrationByAppName and cli is set to prompt', async () => { sinon.stub(request, 'get').callsFake(async opts => { if (opts.url === `https://graph.microsoft.com/v1.0/applications?$filter=displayName eq '${formatting.encodeQueryParameter(appName)}'&$select=id`) { diff --git a/src/utils/entraApp.ts b/src/utils/entraApp.ts index 42542bd6b1c..5c903806803 100644 --- a/src/utils/entraApp.ts +++ b/src/utils/entraApp.ts @@ -485,8 +485,15 @@ export const entraApp = { responseType: 'json' }; - const app = await request.get(requestOptions); + try { + return await request.get(requestOptions); + } + catch (error: any) { + if (error?.response?.status === 404) { + throw Error(`App with objectId '${objectId}' not found in Microsoft Entra ID.`); + } - return app; + throw error; + } } }; \ No newline at end of file