Skip to content

Commit

Permalink
fix: Let Serverless Framework handle thrown error (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo authored and tbarlow12 committed Aug 16, 2019
1 parent 20f1579 commit de798b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/plugins/login/azureLoginPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,17 @@ describe("Login Plugin", () => {
expect(sls.variables["subscriptionId"]).toEqual("azureSubId");
});

it("logs an error from authentication and exits process", async () => {
it("logs an error from authentication and crashes with it", async () => {
unsetServicePrincipalEnvVariables();
process.exit = jest.fn() as any;
const errorMessage = "This is my error message";
const error = new Error("This is my error message")
AzureLoginService.interactiveLogin = jest.fn(() => {
throw new Error(errorMessage);
throw error;
});
const sls = MockFactory.createTestServerless();
await invokeLoginHook(false, sls);
await expect(invokeLoginHook(false, sls)).rejects.toThrow(error);
expect(AzureLoginService.interactiveLogin).toBeCalled()
expect(AzureLoginService.servicePrincipalLogin).not.toBeCalled();
expect(sls.cli.log).lastCalledWith(`Error: ${errorMessage}`);
expect(process.exit).toBeCalledWith(0);
expect(sls.cli.log).lastCalledWith("Error logging into azure");
});

it("Uses the user specified subscription ID", async () => {
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/login/azureLoginPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export class AzureLoginPlugin extends AzureBasePlugin<AzureLoginOptions> {
}
catch (e) {
this.log("Error logging into azure");
this.log(`${e}`);
process.exit(0);
throw e; // Let Serverless Framework communicate the error
}
}
}

0 comments on commit de798b6

Please sign in to comment.