@@ -75,19 +75,23 @@ export const notifyContactCreated = async (
7575 const payload = createPayload ( name , email , url ) ;
7676 const payloadStringify = JSON . stringify ( payload ) ;
7777
78- const result = await fetch ( "https://slack.com/api/chat.postMessage" , {
79- method : "POST" ,
80- body : payloadStringify ,
81- headers : {
82- "Content-Type" : "application/json; charset=utf-8" ,
83- "Content-Length" : payloadStringify . length . toString ( ) ,
84- Authorization : `Bearer ${ SLACK_BOT_TOKEN } ` ,
85- Accept : "application/json" ,
86- } ,
87- } ) ;
88- const realResponse = await result . json ( ) ;
89- if ( result . status !== 200 || ! realResponse . ok ) {
90- console . error ( "Could not send notification message to Slack" ) ;
78+ try {
79+ const result = await fetch ( "https://slack.com/api/chat.postMessage" , {
80+ method : "POST" ,
81+ body : payloadStringify ,
82+ headers : {
83+ "Content-Type" : "application/json; charset=utf-8" ,
84+ "Content-Length" : payloadStringify . length . toString ( ) ,
85+ Authorization : `Bearer ${ SLACK_BOT_TOKEN } ` ,
86+ Accept : "application/json" ,
87+ } ,
88+ } ) ;
89+ const realResponse = await result . json ( ) ;
90+ if ( result . status !== 200 || ! realResponse . ok ) {
91+ console . error ( "Could not send notification message to Slack" ) ;
92+ }
93+ } catch ( error ) {
94+ console . error ( "Could not send notification message to Slack" , error ) ;
9195 }
9296} ;
9397
@@ -99,18 +103,22 @@ export const notifyContactError = async (
99103 const payload = createErrorPayload ( name , email , content ) ;
100104 const payloadStringify = JSON . stringify ( payload ) ;
101105
102- const result = await fetch ( "https://slack.com/api/chat.postMessage" , {
103- method : "POST" ,
104- body : payloadStringify ,
105- headers : {
106- "Content-Type" : "application/json; charset=utf-8" ,
107- "Content-Length" : payloadStringify . length . toString ( ) ,
108- Authorization : `Bearer ${ SLACK_BOT_TOKEN } ` ,
109- Accept : "application/json" ,
110- } ,
111- } ) ;
112- const realResponse = await result . json ( ) ;
113- if ( result . status !== 200 || ! realResponse . ok ) {
114- console . error ( "Could not send notification message to Slack" ) ;
106+ try {
107+ const result = await fetch ( "https://slack.com/api/chat.postMessage" , {
108+ method : "POST" ,
109+ body : payloadStringify ,
110+ headers : {
111+ "Content-Type" : "application/json; charset=utf-8" ,
112+ "Content-Length" : payloadStringify . length . toString ( ) ,
113+ Authorization : `Bearer ${ SLACK_BOT_TOKEN } ` ,
114+ Accept : "application/json" ,
115+ } ,
116+ } ) ;
117+ const realResponse = await result . json ( ) ;
118+ if ( result . status !== 200 || ! realResponse . ok ) {
119+ console . error ( "Could not send notification message to Slack" ) ;
120+ }
121+ } catch ( error ) {
122+ console . error ( "Could not send notification message to Slack" , error ) ;
115123 }
116124} ;
0 commit comments