Skip to content

Commit 2c2d4ce

Browse files
committed
log on error
1 parent 4286cf7 commit 2c2d4ce

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

spec/CloudCode.spec.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,13 +3186,11 @@ describe('sendMail', () => {
31863186
});
31873187

31883188
it('cannot send email without adapter', async () => {
3189-
try {
3190-
await Parse.Cloud.sendMail({});
3191-
fail('Should have failed to send emails.');
3192-
} catch (e) {
3193-
expect(e).toBe(
3194-
'Failed to send email because no mail adapter is configured for Parse Server.'
3195-
);
3196-
}
3189+
const logger = require('../lib/logger').logger;
3190+
spyOn(logger, 'warn').and.callFake(() => {});
3191+
await Parse.Cloud.sendMail({});
3192+
expect(logger.warn).toHaveBeenCalledWith(
3193+
'Failed to send email because no mail adapter is configured for Parse Server.'
3194+
);
31973195
});
31983196
});

src/cloud-code/Parse.Cloud.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,12 @@ ParseCloud.beforeConnect = function (handler, validationHandler) {
551551
ParseCloud.sendMail = function (data) {
552552
const config = Config.get(Parse.applicationId) || {};
553553
const emailAdapter = config.userController.adapter;
554-
if (!emailAdapter) {
555-
throw 'Failed to send email because no mail adapter is configured for Parse Server.';
554+
if (emailAdapter) {
555+
return emailAdapter.sendMail(data);
556556
}
557-
return emailAdapter.sendMail(data);
557+
config.loggerController.warn(
558+
'Failed to send email because no mail adapter is configured for Parse Server.'
559+
);
558560
};
559561

560562
/**

0 commit comments

Comments
 (0)