Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/utils/entraApp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`) {
Expand Down
11 changes: 9 additions & 2 deletions src/utils/entraApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,15 @@ export const entraApp = {
responseType: 'json'
};

const app = await request.get<Application>(requestOptions);
try {
return await request.get<Application>(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;
}
}
};