Skip to content

Commit 908f32f

Browse files
authored
ci: enable no-useless-catch rule (#935)
1 parent 151215c commit 908f32f

File tree

8 files changed

+187
-217
lines changed

8 files changed

+187
-217
lines changed

.eslintrc

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
"unicorn/prefer-set-has": "warn",
3535
"unicorn/no-process-exit": "warn",
3636
"unicorn/prefer-switch": "warn",
37-
"unicorn/prefer-string-slice": "warn",
38-
"no-useless-catch": "warn",
39-
"unicorn/prefer-object-from-entries": "warn"
37+
"unicorn/prefer-string-slice": "warn"
4038
},
4139
"overrides": [
4240
{

src/components/notification/channel/dingtalk.ts

+57-61
Original file line numberDiff line numberDiff line change
@@ -32,82 +32,78 @@ export const sendDingtalk = async (
3232
data: DingtalkData,
3333
message: NotificationMessage
3434
): Promise<AxiosResponse> => {
35-
try {
36-
const notificationType =
37-
message.meta.type[0].toUpperCase() + message.meta.type.substring(1)
35+
const notificationType =
36+
message.meta.type[0].toUpperCase() + message.meta.type.substring(1)
3837

39-
let content
40-
let bodyJson
41-
switch (message.meta.type) {
42-
case 'incident':
43-
case 'recovery': {
44-
content = `New ${notificationType} event from Monika\n\n${message.body}`
45-
bodyJson = {
46-
msgtype: 'text',
47-
text: {
48-
content: content,
49-
},
50-
}
51-
break
38+
let content
39+
let bodyJson
40+
switch (message.meta.type) {
41+
case 'incident':
42+
case 'recovery': {
43+
content = `New ${notificationType} event from Monika\n\n${message.body}`
44+
bodyJson = {
45+
msgtype: 'text',
46+
text: {
47+
content: content,
48+
},
5249
}
53-
case 'status-update': {
54-
content = `Status Update ${format(
55-
new Date(),
56-
'yyyy-MM-dd HH:mm:ss XXX'
57-
)}\n
50+
break
51+
}
52+
case 'status-update': {
53+
content = `Status Update ${format(
54+
new Date(),
55+
'yyyy-MM-dd HH:mm:ss XXX'
56+
)}\n
5857
Host: ${message.meta.monikaInstance}\n
5958
Number of Probes: ${message.meta.numberOfProbes}\n
6059
Maximum Response Time: ${message.meta.maxResponseTime} ms in the last ${
61-
message.meta.responseTimelogLifeTimeInHour
62-
} hours\n
60+
message.meta.responseTimelogLifeTimeInHour
61+
} hours\n
6362
Minimum Response Time: ${message.meta.minResponseTime} ms in the last ${
64-
message.meta.responseTimelogLifeTimeInHour
65-
} hours\n
63+
message.meta.responseTimelogLifeTimeInHour
64+
} hours\n
6665
Average Response Time: ${message.meta.averageResponseTime} ms in the last ${
67-
message.meta.responseTimelogLifeTimeInHour
68-
} hours\n
66+
message.meta.responseTimelogLifeTimeInHour
67+
} hours\n
6968
Incidents: ${message.meta.numberOfIncidents} in the last 24 hours\n
7069
Recoveries: ${message.meta.numberOfRecoveries} in the last 24 hours\n
7170
Notifications: ${message.meta.numberOfSentNotifications}\n
7271
\n
7372
`
74-
const indexTweet = message.body.indexOf('<a href')
75-
let tweet = message.body.substring(indexTweet)
76-
tweet = tweet.replace('<a href=', '[Tweet this status!](')
77-
tweet = tweet.replace('Tweet this status!</a>', ')')
73+
const indexTweet = message.body.indexOf('<a href')
74+
let tweet = message.body.substring(indexTweet)
75+
tweet = tweet.replace('<a href=', '[Tweet this status!](')
76+
tweet = tweet.replace('Tweet this status!</a>', ')')
7877

79-
bodyJson = {
80-
msgtype: 'markdown',
81-
markdown: {
82-
title: message.meta.type,
83-
text: content + tweet,
84-
},
85-
}
86-
break
78+
bodyJson = {
79+
msgtype: 'markdown',
80+
markdown: {
81+
title: message.meta.type,
82+
text: content + tweet,
83+
},
8784
}
88-
89-
default:
90-
content = message.body
91-
bodyJson = {
92-
msgtype: 'text',
93-
text: {
94-
content: content,
95-
},
96-
}
97-
break
85+
break
9886
}
9987

100-
const res = await sendHttpRequest({
101-
method: 'POST',
102-
url: `https://oapi.dingtalk.com/robot/send?access_token=${data.access_token}`,
103-
headers: {
104-
'Content-Type': 'application/json',
105-
},
106-
data: bodyJson,
107-
})
108-
109-
return res
110-
} catch (error) {
111-
throw error
88+
default:
89+
content = message.body
90+
bodyJson = {
91+
msgtype: 'text',
92+
text: {
93+
content: content,
94+
},
95+
}
96+
break
11297
}
98+
99+
const res = await sendHttpRequest({
100+
method: 'POST',
101+
url: `https://oapi.dingtalk.com/robot/send?access_token=${data.access_token}`,
102+
headers: {
103+
'Content-Type': 'application/json',
104+
},
105+
data: bodyJson,
106+
})
107+
108+
return res
113109
}

src/components/notification/channel/gotify.ts

+31-35
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,41 @@ export const sendGotify = async (
3131
data: GotifyData,
3232
message: NotificationMessage
3333
) => {
34-
try {
35-
const notificationType =
36-
message.meta.type[0].toUpperCase() + message.meta.type.substring(1)
34+
const notificationType =
35+
message.meta.type[0].toUpperCase() + message.meta.type.substring(1)
3736

38-
let title
39-
let content
40-
switch (message.meta.type) {
41-
case 'incident':
42-
case 'recovery': {
43-
title = message.meta.type.toUpperCase() + ': '
44-
content = `New ${notificationType} event from Monika\n\n${message.body}`
45-
break
46-
}
47-
default:
48-
title = ''
49-
content = message.body
50-
break
37+
let title
38+
let content
39+
switch (message.meta.type) {
40+
case 'incident':
41+
case 'recovery': {
42+
title = message.meta.type.toUpperCase() + ': '
43+
content = `New ${notificationType} event from Monika\n\n${message.body}`
44+
break
5145
}
46+
default:
47+
title = ''
48+
content = message.body
49+
break
50+
}
5251

53-
if (message.meta.url) {
54-
title += `[${message.meta.url}] `
55-
}
52+
if (message.meta.url) {
53+
title += `[${message.meta.url}] `
54+
}
5655

57-
title += `${message.summary}`
56+
title += `${message.summary}`
5857

59-
const res = await axios.request({
60-
method: 'POST',
61-
url: `${data.url}/message?token=${data.token}`,
62-
headers: {
63-
'Content-Type': 'application/json',
64-
},
65-
data: {
66-
title,
67-
message: content,
68-
},
69-
})
58+
const res = await axios.request({
59+
method: 'POST',
60+
url: `${data.url}/message?token=${data.token}`,
61+
headers: {
62+
'Content-Type': 'application/json',
63+
},
64+
data: {
65+
title,
66+
message: content,
67+
},
68+
})
7069

71-
return res
72-
} catch (error) {
73-
throw error
74-
}
70+
return res
7571
}

src/components/notification/channel/opsgenie.ts

+33-37
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,41 @@ export const sendOpsgenie = async (
3131
data: OpsgenieData,
3232
message: NotificationMessage
3333
): Promise<AxiosResponse> => {
34-
try {
35-
const notificationType =
36-
message.meta.type[0].toUpperCase() + message.meta.type.substring(1)
34+
const notificationType =
35+
message.meta.type[0].toUpperCase() + message.meta.type.substring(1)
3736

38-
let content
39-
let title
40-
switch (message.meta.type) {
41-
case 'incident':
42-
case 'recovery': {
43-
title = `New ${notificationType} event from Monika`
44-
content = `New ${notificationType} event from Monika\n\n${message.body}`
45-
break
46-
}
47-
case 'status-update': {
48-
title = `Monika status update`
49-
content = `New ${notificationType} event from Monika\n\n${message.body}`
50-
break
51-
}
52-
default:
53-
title = `Monika ${message.meta.type}`
54-
content = message.body
55-
break
37+
let content
38+
let title
39+
switch (message.meta.type) {
40+
case 'incident':
41+
case 'recovery': {
42+
title = `New ${notificationType} event from Monika`
43+
content = `New ${notificationType} event from Monika\n\n${message.body}`
44+
break
5645
}
46+
case 'status-update': {
47+
title = `Monika status update`
48+
content = `New ${notificationType} event from Monika\n\n${message.body}`
49+
break
50+
}
51+
default:
52+
title = `Monika ${message.meta.type}`
53+
content = message.body
54+
break
55+
}
5756

58-
const res = await sendHttpRequest({
59-
method: 'POST',
60-
url: `https://api.opsgenie.com/v2/alerts`,
61-
headers: {
62-
'Content-Type': 'application/json',
63-
Authorization: `GenieKey ${data.geniekey}`,
64-
},
65-
data: {
66-
message: title,
67-
description: content,
68-
},
69-
})
57+
const res = await sendHttpRequest({
58+
method: 'POST',
59+
url: `https://api.opsgenie.com/v2/alerts`,
60+
headers: {
61+
'Content-Type': 'application/json',
62+
Authorization: `GenieKey ${data.geniekey}`,
63+
},
64+
data: {
65+
message: title,
66+
description: content,
67+
},
68+
})
7069

71-
return res
72-
} catch (error) {
73-
throw error
74-
}
70+
return res
7571
}

src/components/notification/channel/pushover.ts

+27-31
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,35 @@ export const sendPushover = async (
3131
data: PushoverData,
3232
message: NotificationMessage
3333
): Promise<AxiosResponse> => {
34-
try {
35-
const notificationType =
36-
message.meta.type[0].toUpperCase() + message.meta.type.slice(1)
34+
const notificationType =
35+
message.meta.type[0].toUpperCase() + message.meta.type.slice(1)
3736

38-
let content
39-
switch (message.meta.type) {
40-
case 'incident':
41-
case 'recovery': {
42-
content = `New ${notificationType} event from Monika\n\n${message.body}`
43-
break
44-
}
45-
46-
default:
47-
content = message.body
48-
break
37+
let content
38+
switch (message.meta.type) {
39+
case 'incident':
40+
case 'recovery': {
41+
content = `New ${notificationType} event from Monika\n\n${message.body}`
42+
break
4943
}
5044

51-
const res = await sendHttpRequest({
52-
method: 'POST',
53-
url: `https://api.pushover.net/1/messages.json`,
54-
headers: {
55-
'Content-Type': 'application/json',
56-
},
57-
data: {
58-
user: data.user,
59-
token: data.token,
60-
message: content,
61-
html: 1,
62-
},
63-
})
64-
65-
return res
66-
} catch (error) {
67-
throw error
45+
default:
46+
content = message.body
47+
break
6848
}
49+
50+
const res = await sendHttpRequest({
51+
method: 'POST',
52+
url: `https://api.pushover.net/1/messages.json`,
53+
headers: {
54+
'Content-Type': 'application/json',
55+
},
56+
data: {
57+
user: data.user,
58+
token: data.token,
59+
message: content,
60+
html: 1,
61+
},
62+
})
63+
64+
return res
6965
}

0 commit comments

Comments
 (0)