Skip to content

Commit

Permalink
Merge pull request #8910 from OfficeDev/chyuan/detail-error-message-f…
Browse files Browse the repository at this point in the history
…or-bot

fix: no detail error message when botAadApp/create failed
  • Loading branch information
adashen authored Jun 5, 2023
2 parents 6cf3b73 + d4187d7 commit 4375db5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit 4375db5

Please sign in to comment.