@@ -9,6 +9,7 @@ const _ = require('lodash');
9
9
const config = require ( 'config' ) ;
10
10
const emailServer = require ( '../index' ) ;
11
11
const service = require ( './service' ) ;
12
+ const logger = require ( '../src/common/logger' ) ;
12
13
13
14
// set configuration for the server, see ../config/default.js for available config parameters
14
15
// setConfig should be called before initDatabase and start functions
@@ -21,16 +22,19 @@ emailServer.setConfig({ LOG_LEVEL: 'debug' });
21
22
// the message is JSON event message,
22
23
// the callback is function(error, templateId), where templateId is the used SendGrid template id
23
24
const handler = ( topic , message , callback ) => {
24
- const templateId = config . TEMPLATE_MAP [ topic ] ;
25
- if ( templateId === undefined ) {
25
+ let templateId = config . TEMPLATE_MAP [ topic ] ;
26
+ templateId = _ . get ( message , config . PAYLOAD_SENDGRID_TEMPLATE_KEY , templateId ) ;
27
+ if ( ! templateId ) {
26
28
return callback ( null , { success : false , error : `Template not found for topic ${ topic } ` } ) ;
27
29
}
28
30
29
- service . sendEmail ( templateId , message ) . then ( ( ) => {
30
- callback ( null , { success : true } ) ;
31
- } ) . catch ( ( err ) => {
32
- callback ( null , { success : false , error : err } ) ;
33
- } ) ;
31
+ service . sendEmail ( templateId , message ) . then ( ( ) => {
32
+ callback ( null , { success : true } ) ;
33
+ } ) . catch ( ( err ) => {
34
+ logger . error ( "Error occurred in sendgrid api calling:" , err ) ;
35
+ callback ( null , { success : false , error : err } ) ;
36
+ } ) ;
37
+
34
38
} ;
35
39
36
40
// init all events
0 commit comments