Skip to content

Commit e5906b0

Browse files
authored
Improves error when retrieving app by objectId. Closes #6884
1 parent b2420bd commit e5906b0

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/utils/entraApp.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ describe('utils/entraApp', () => {
9191
assert.deepStrictEqual(actual.displayName, appName);
9292
});
9393

94+
it('throws error message when no application was found using getAppRegistrationByObjectId', async () => {
95+
const error = { response: { status: 404 } };
96+
sinon.stub(request, 'get').rejects(error);
97+
98+
await assert.rejects(entraApp.getAppRegistrationByObjectId(appObjectId),
99+
new Error(`App with objectId '${appObjectId}' not found in Microsoft Entra ID.`));
100+
});
101+
94102
it('handles selecting single application when multiple applications with the specified name found using getAppRegistrationByAppName and cli is set to prompt', async () => {
95103
sinon.stub(request, 'get').callsFake(async opts => {
96104
if (opts.url === `https://graph.microsoft.com/v1.0/applications?$filter=displayName eq '${formatting.encodeQueryParameter(appName)}'&$select=id`) {

src/utils/entraApp.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,15 @@ export const entraApp = {
485485
responseType: 'json'
486486
};
487487

488-
const app = await request.get<Application>(requestOptions);
488+
try {
489+
return await request.get<Application>(requestOptions);
490+
}
491+
catch (error: any) {
492+
if (error?.response?.status === 404) {
493+
throw Error(`App with objectId '${objectId}' not found in Microsoft Entra ID.`);
494+
}
489495

490-
return app;
496+
throw error;
497+
}
491498
}
492499
};

0 commit comments

Comments
 (0)