@@ -6,14 +6,20 @@ const {
6
6
createTrelloCard,
7
7
isValidSecret,
8
8
createDataFromBodyText,
9
- createDataFromJSON
9
+ createDataFromJSON,
10
+ notifyFailure
10
11
} = require ( './utils' )
11
12
13
+ const raiseError = message => {
14
+ console . log ( message )
15
+ notifyFailure ( message )
16
+ }
17
+
12
18
exports . handler = async ( event , context ) => {
13
19
console . log ( '=== request accepted ===' )
14
20
15
21
if ( event . httpMethod !== 'POST' ) {
16
- console . log ( 'ERR: method is not post' )
22
+ raiseError ( 'ERR: method is not post' )
17
23
return {
18
24
statusCode : 400 ,
19
25
body : 'Must POST to this function'
@@ -26,7 +32,7 @@ exports.handler = async (event, context) => {
26
32
27
33
// check params
28
34
if ( ! urlSource || ! appSecret ) {
29
- console . log ( 'ERR: params not enough' )
35
+ raiseError ( 'ERR: params not enough' )
30
36
return {
31
37
statusCode : 400 ,
32
38
body : 'params not enough'
@@ -35,7 +41,7 @@ exports.handler = async (event, context) => {
35
41
36
42
// need valid appSecret
37
43
if ( ! isValidSecret ( appSecret ) ) {
38
- console . log ( 'ERR: invalid appSecret' )
44
+ raiseError ( 'ERR: invalid appSecret' )
39
45
return {
40
46
statusCode : 400 ,
41
47
body : 'invalid appSecret'
@@ -49,7 +55,7 @@ exports.handler = async (event, context) => {
49
55
const html = await fetchHtml ( urlSource )
50
56
formattedPageText = createFormattedTextFromHtml ( html )
51
57
} catch ( err ) {
52
- console . log ( 'ERR: fetching page failed' )
58
+ raiseError ( 'ERR: fetching page failed' )
53
59
console . log ( err )
54
60
// something wrong
55
61
return {
@@ -70,7 +76,7 @@ exports.handler = async (event, context) => {
70
76
71
77
// something wrong
72
78
if ( ! response . ok ) {
73
- console . log ( 'ERR: trello api says response.ok is false' )
79
+ raiseError ( 'ERR: trello api says response.ok is false' )
74
80
// NOT res.status >= 200 && res.status < 300
75
81
const data = await response . json ( )
76
82
console . log ( data )
@@ -91,7 +97,7 @@ exports.handler = async (event, context) => {
91
97
}
92
98
} catch ( err ) {
93
99
// something wrong
94
- console . log ( 'ERR: request failed on creating card' )
100
+ raiseError ( 'ERR: request failed on creating card' )
95
101
console . log ( err . message )
96
102
console . log ( err )
97
103
return {
0 commit comments