Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no detail error message when botAadApp/create failed #8910

Merged
merged 3 commits into from
Jun 5, 2023
Merged
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
6 changes: 5 additions & 1 deletion packages/fx-core/src/component/driver/botAadApp/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class CreateBotAadAppDriver implements StepDriver {
output: outputs,
summaries: [summary],
};
} catch (error) {
} catch (error: any) {
if (error instanceof UserError || error instanceof SystemError) {
context.logProvider?.error(
getLocalizedString(logMessageKeys.failExecuteDriver, actionName, error.displayMessage)
Expand All @@ -161,6 +161,10 @@ export class CreateBotAadAppDriver implements StepDriver {
}
}

if (error.name === "AadCreateAppError") {
throw new UnhandledUserError(new Error(error.details[0]), actionName);
}

const message = JSON.stringify(error);
context.logProvider?.error(
getLocalizedString(logMessageKeys.failExecuteDriver, actionName, message)
Expand Down
25 changes: 25 additions & 0 deletions packages/fx-core/tests/component/driver/botAadApp/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
UnhandledError,
UnhandledUserError,
} from "../../../../src/error/common";
import { CreateAADAppError } from "../../../../src/component/resource/botService/errors";

chai.use(chaiAsPromised);
const expect = chai.expect;
Expand Down Expand Up @@ -209,6 +210,30 @@ describe("botAadAppCreate", async () => {
.and.is.instanceOf(UserError);
});

it("should show detailed error when GraphClient throws CreateAADAppError", async () => {
sinon.stub(GraphClient, "registerAadApp").callsFake(() => {
throw new CreateAADAppError({
response: {
data: {
error: {
message: "Quota exceeded",
},
},
},
});
});
const args: any = {
name: expectedDisplayName,
};
await expect(createBotAadAppDriver.handler(args, mockedDriverContext)).to.be.rejected.then(
(error) => {
console.log(JSON.stringify(error));
expect(error instanceof UnhandledUserError).to.be.true;
expect(error.message).contains("Quota exceeded");
}
);
});

it("should be good when reusing existing bot in env", async () => {
envRestore = mockedEnv({
[outputKeys.BOT_ID]: expectedClientId,
Expand Down