Skip to content

Commit

Permalink
fix: report email as not sent to fe if it throws (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikOseberg committed May 11, 2021
1 parent c9f67cc commit 52d3e9e
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/lib/routes/admin-api/user-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export default class UserAdminController extends Controller {
resetTokenService,
sessionService,
}: Pick<
IUnleashServices,
| 'userService'
| 'accessService'
| 'emailService'
| 'resetTokenService'
| 'sessionService'
IUnleashServices,
| 'userService'
| 'accessService'
| 'emailService'
| 'resetTokenService'
| 'sessionService'
>,
) {
super(config);
Expand Down Expand Up @@ -137,13 +137,22 @@ export default class UserAdminController extends Controller {
user.email,
);

let emailSent = false;
const emailConfigured = this.emailService.configured();
if (emailConfigured) {
await this.emailService.sendGettingStartedMail(
createdUser.name,
createdUser.email,
inviteLink.toString(),
);
try {
await this.emailService.sendGettingStartedMail(
createdUser.name,
createdUser.email,
inviteLink.toString(),
);
emailSent = true;
} catch (e) {
this.logger.warn(
'email was configured, but sending failed due to: ',
e,
);
}
} else {
this.logger.warn(
'email was not sent to the user because email configuration is lacking',
Expand All @@ -153,7 +162,7 @@ export default class UserAdminController extends Controller {
res.status(201).send({
...createdUser,
inviteLink,
emailSent: emailConfigured,
emailSent,
rootRole,
});
} catch (e) {
Expand Down

0 comments on commit 52d3e9e

Please sign in to comment.