Skip to content

Commit 4f552d3

Browse files
committed
fix: add discord alert on all errors
1 parent 85b67f5 commit 4f552d3

19 files changed

Lines changed: 342 additions & 19 deletions

File tree

cloudflare_workers/api/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { sentry } from '@hono/sentry'
44
import { HTTPException } from 'hono/http-exception'
55
import { logger } from 'hono/logger'
66
import { Hono } from 'hono/tiny'
7+
import { sendDiscordAlert } from 'supabase/functions/_backend/utils/discord.ts'
8+
import { backgroundTask } from 'supabase/functions/_backend/utils/utils.ts'
79
import { version } from '../../package.json'
810
import { app as config } from '../../supabase/functions/_backend/private/config.ts'
911
import { app as create_device } from '../../supabase/functions/_backend/private/create_device.ts'
@@ -114,7 +116,7 @@ app.all('*', (c) => {
114116
console.log('Not found', c.req.url)
115117
return c.json({ error: 'Not Found' }, 404)
116118
})
117-
app.onError((e, c) => {
119+
app.onError(async (e, c) => {
118120
console.log('app onError', e)
119121
c.get('sentry')?.captureException(e)
120122
if (e instanceof HTTPException) {
@@ -124,6 +126,21 @@ app.onError((e, c) => {
124126
}
125127
return c.json({ status: 'Internal Server Error', response: e.getResponse(), error: JSON.stringify(e), message: e.message }, e.status)
126128
}
129+
await backgroundTask(c as any, sendDiscordAlert(c as any, {
130+
content: 'Cloudflare Worker Error',
131+
embeds: [
132+
{
133+
title: 'Failed to process',
134+
description: 'Cloudflare Worker Error',
135+
fields: [
136+
{
137+
name: 'Error',
138+
value: JSON.stringify(e),
139+
},
140+
],
141+
},
142+
],
143+
}))
127144
return c.json({ status: 'Internal Server Error', error: JSON.stringify(e), message: e.message }, 500)
128145
})
129146

cloudflare_workers/files/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { sentry } from '@hono/sentry'
44
import { HTTPException } from 'hono/http-exception'
55
import { logger } from 'hono/logger'
66
import { Hono } from 'hono/tiny'
7+
import { sendDiscordAlert } from 'supabase/functions/_backend/utils/discord.ts'
8+
import { backgroundTask } from 'supabase/functions/_backend/utils/utils.ts'
79
import { version } from '../../package.json'
810
import { app as download_link } from '../../supabase/functions/_backend/private/download_link.ts'
911
import { app as files } from '../../supabase/functions/_backend/private/files.ts'
@@ -30,7 +32,7 @@ app.all('*', (c) => {
3032
console.log('Not found', c.req.url)
3133
return c.json({ error: 'Not Found' }, 404)
3234
})
33-
app.onError((e, c) => {
35+
app.onError(async (e, c) => {
3436
console.log('app onError', e)
3537
c.get('sentry')?.captureException(e)
3638
if (e instanceof HTTPException) {
@@ -40,6 +42,21 @@ app.onError((e, c) => {
4042
}
4143
return c.json({ status: 'Internal Server Error', response: e.getResponse(), error: JSON.stringify(e), message: e.message }, e.status)
4244
}
45+
await backgroundTask(c as any, sendDiscordAlert(c as any, {
46+
content: 'Cloudflare Worker Error',
47+
embeds: [
48+
{
49+
title: 'Failed to process',
50+
description: 'Cloudflare Worker Error',
51+
fields: [
52+
{
53+
name: 'Error',
54+
value: JSON.stringify(e),
55+
},
56+
],
57+
},
58+
],
59+
}))
4360
return c.json({ status: 'Internal Server Error', error: JSON.stringify(e), message: e.message }, 500)
4461
})
4562

cloudflare_workers/plugin/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { sentry } from '@hono/sentry'
44
import { HTTPException } from 'hono/http-exception'
55
import { logger } from 'hono/logger'
66
import { Hono } from 'hono/tiny'
7+
import { sendDiscordAlert } from 'supabase/functions/_backend/utils/discord.ts'
8+
import { backgroundTask } from 'supabase/functions/_backend/utils/utils.ts'
79
import { version } from '../../package.json'
810
import { app as channel_self } from '../../supabase/functions/_backend/plugins/channel_self.ts'
911
import { app as stats } from '../../supabase/functions/_backend/plugins/stats.ts'
@@ -41,7 +43,7 @@ app.all('*', (c) => {
4143
console.log('Not found', c.req.url)
4244
return c.json({ error: 'Not Found' }, 404)
4345
})
44-
app.onError((e, c) => {
46+
app.onError(async (e, c) => {
4547
console.log('app onError', e)
4648
c.get('sentry')?.captureException(e)
4749
if (e instanceof HTTPException) {
@@ -51,6 +53,21 @@ app.onError((e, c) => {
5153
}
5254
return c.json({ status: 'Internal Server Error', response: e.getResponse(), error: JSON.stringify(e), message: e.message }, e.status)
5355
}
56+
await backgroundTask(c as any, sendDiscordAlert(c as any, {
57+
content: 'Cloudflare Worker Error',
58+
embeds: [
59+
{
60+
title: 'Failed to process',
61+
description: 'Cloudflare Worker Error',
62+
fields: [
63+
{
64+
name: 'Error',
65+
value: JSON.stringify(e),
66+
},
67+
],
68+
},
69+
],
70+
}))
5471
return c.json({ status: 'Internal Server Error', error: JSON.stringify(e), message: e.message }, 500)
5572
})
5673

supabase/functions/apikey/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { logger } from 'hono/logger'
55
import { requestId } from 'hono/request-id'
66
import { Hono } from 'hono/tiny'
77
import { app } from '../_backend/public/apikey/index.ts'
8+
import { sendDiscordAlert } from '../_backend/utils/discord.ts'
9+
import { backgroundTask } from '../_backend/utils/utils.ts'
810

911
const functionName = 'apikey'
1012
const appGlobal = new Hono<MiddlewareKeyVariables>().basePath(`/${functionName}`)
@@ -24,7 +26,7 @@ appGlobal.all('*', (c) => {
2426
console.log('Not found', c.req.url)
2527
return c.json({ error: 'Not Found' }, 404)
2628
})
27-
appGlobal.onError((e, c) => {
29+
appGlobal.onError(async (e, c) => {
2830
console.log('app onError', e)
2931
c.get('sentry')?.captureException(e)
3032
if (e instanceof HTTPException) {
@@ -34,6 +36,21 @@ appGlobal.onError((e, c) => {
3436
}
3537
return c.json({ status: 'Internal Server Error', response: e.getResponse(), error: JSON.stringify(e), message: e.message }, e.status)
3638
}
39+
await backgroundTask(c as any, sendDiscordAlert(c as any, {
40+
content: `Function: ${functionName}`,
41+
embeds: [
42+
{
43+
title: `Failed to process ${functionName}`,
44+
description: `Function: ${functionName}`,
45+
fields: [
46+
{
47+
name: 'Error',
48+
value: JSON.stringify(e),
49+
},
50+
],
51+
},
52+
],
53+
}))
3754
return c.json({ status: 'Internal Server Error', error: JSON.stringify(e), message: e.message }, 500)
3855
})
3956
Deno.serve(appGlobal.fetch)

supabase/functions/app/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { logger } from 'hono/logger'
55
import { requestId } from 'hono/request-id'
66
import { Hono } from 'hono/tiny'
77
import { app } from '../_backend/public/app/index.ts'
8+
import { sendDiscordAlert } from '../_backend/utils/discord.ts'
9+
import { backgroundTask } from '../_backend/utils/utils.ts'
810

911
const functionName = 'app'
1012
const appGlobal = new Hono<MiddlewareKeyVariables>().basePath(`/${functionName}`)
@@ -24,7 +26,7 @@ appGlobal.all('*', (c) => {
2426
console.log('Not found', c.req.url)
2527
return c.json({ error: 'Not Found' }, 404)
2628
})
27-
appGlobal.onError((e, c) => {
29+
appGlobal.onError(async (e, c) => {
2830
console.log('app onError', e)
2931
c.get('sentry')?.captureException(e)
3032
if (e instanceof HTTPException) {
@@ -34,6 +36,21 @@ appGlobal.onError((e, c) => {
3436
}
3537
return c.json({ status: 'Internal Server Error', response: e.getResponse(), error: JSON.stringify(e), message: e.message }, e.status)
3638
}
39+
await backgroundTask(c as any, sendDiscordAlert(c as any, {
40+
content: `Function: ${functionName}`,
41+
embeds: [
42+
{
43+
title: `Failed to process ${functionName}`,
44+
description: `Function: ${functionName}`,
45+
fields: [
46+
{
47+
name: 'Error',
48+
value: JSON.stringify(e),
49+
},
50+
],
51+
},
52+
],
53+
}))
3754
return c.json({ status: 'Internal Server Error', error: JSON.stringify(e), message: e.message }, 500)
3855
})
3956
Deno.serve(appGlobal.fetch)

supabase/functions/bundle/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { logger } from 'hono/logger'
55
import { requestId } from 'hono/request-id'
66
import { Hono } from 'hono/tiny'
77
import { app } from '../_backend/public/bundle/index.ts'
8+
import { sendDiscordAlert } from '../_backend/utils/discord.ts'
9+
import { backgroundTask } from '../_backend/utils/utils.ts'
810

911
const functionName = 'bundle'
1012
const appGlobal = new Hono<MiddlewareKeyVariables>().basePath(`/${functionName}`)
@@ -24,7 +26,7 @@ appGlobal.all('*', (c) => {
2426
console.log('Not found', c.req.url)
2527
return c.json({ error: 'Not Found' }, 404)
2628
})
27-
appGlobal.onError((e, c) => {
29+
appGlobal.onError(async (e, c) => {
2830
console.log('app onError', e)
2931
c.get('sentry')?.captureException(e)
3032
if (e instanceof HTTPException) {
@@ -34,6 +36,21 @@ appGlobal.onError((e, c) => {
3436
}
3537
return c.json({ status: 'Internal Server Error', response: e.getResponse(), error: JSON.stringify(e), message: e.message }, e.status)
3638
}
39+
await backgroundTask(c as any, sendDiscordAlert(c as any, {
40+
content: `Function: ${functionName}`,
41+
embeds: [
42+
{
43+
title: `Failed to process ${functionName}`,
44+
description: `Function: ${functionName}`,
45+
fields: [
46+
{
47+
name: 'Error',
48+
value: JSON.stringify(e),
49+
},
50+
],
51+
},
52+
],
53+
}))
3754
return c.json({ status: 'Internal Server Error', error: JSON.stringify(e), message: e.message }, 500)
3855
})
3956
Deno.serve(appGlobal.fetch)

supabase/functions/channel/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { logger } from 'hono/logger'
55
import { requestId } from 'hono/request-id'
66
import { Hono } from 'hono/tiny'
77
import { app } from '../_backend/public/channel/index.ts'
8+
import { sendDiscordAlert } from '../_backend/utils/discord.ts'
9+
import { backgroundTask } from '../_backend/utils/utils.ts'
810

911
const functionName = 'channel'
1012
const appGlobal = new Hono<MiddlewareKeyVariables>().basePath(`/${functionName}`)
@@ -23,7 +25,7 @@ appGlobal.all('*', (c) => {
2325
console.log('Not found', c.req.url)
2426
return c.json({ error: 'Not Found' }, 404)
2527
})
26-
appGlobal.onError((e, c) => {
28+
appGlobal.onError(async (e, c) => {
2729
console.log('app onError', e)
2830
c.get('sentry')?.captureException(e)
2931
if (e instanceof HTTPException) {
@@ -33,6 +35,21 @@ appGlobal.onError((e, c) => {
3335
}
3436
return c.json({ status: 'Internal Server Error', response: e.getResponse(), error: JSON.stringify(e), message: e.message }, e.status)
3537
}
38+
await backgroundTask(c as any, sendDiscordAlert(c as any, {
39+
content: `Function: ${functionName}`,
40+
embeds: [
41+
{
42+
title: `Failed to process ${functionName}`,
43+
description: `Function: ${functionName}`,
44+
fields: [
45+
{
46+
name: 'Error',
47+
value: JSON.stringify(e),
48+
},
49+
],
50+
},
51+
],
52+
}))
3653
return c.json({ status: 'Internal Server Error', error: JSON.stringify(e), message: e.message }, 500)
3754
})
3855
Deno.serve(appGlobal.fetch)

supabase/functions/channel_self/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { logger } from 'hono/logger'
55
import { requestId } from 'hono/request-id'
66
import { Hono } from 'hono/tiny'
77
import { app } from '../_backend/plugins/channel_self.ts'
8+
import { sendDiscordAlert } from '../_backend/utils/discord.ts'
9+
import { backgroundTask } from '../_backend/utils/utils.ts'
810

911
const functionName = 'channel_self'
1012
const appGlobal = new Hono<MiddlewareKeyVariables>().basePath(`/${functionName}`)
@@ -23,7 +25,7 @@ appGlobal.all('*', (c) => {
2325
console.log('Not found', c.req.url)
2426
return c.json({ error: 'Not Found' }, 404)
2527
})
26-
appGlobal.onError((e, c) => {
28+
appGlobal.onError(async (e, c) => {
2729
console.log('app onError', e)
2830
c.get('sentry')?.captureException(e)
2931
if (e instanceof HTTPException) {
@@ -33,6 +35,21 @@ appGlobal.onError((e, c) => {
3335
}
3436
return c.json({ status: 'Internal Server Error', response: e.getResponse(), error: JSON.stringify(e), message: e.message }, e.status)
3537
}
38+
await backgroundTask(c as any, sendDiscordAlert(c as any, {
39+
content: `Function: ${functionName}`,
40+
embeds: [
41+
{
42+
title: `Failed to process ${functionName}`,
43+
description: `Function: ${functionName}`,
44+
fields: [
45+
{
46+
name: 'Error',
47+
value: JSON.stringify(e),
48+
},
49+
],
50+
},
51+
],
52+
}))
3653
return c.json({ status: 'Internal Server Error', error: JSON.stringify(e), message: e.message }, 500)
3754
})
3855
Deno.serve(appGlobal.fetch)

supabase/functions/device/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { logger } from 'hono/logger'
55
import { requestId } from 'hono/request-id'
66
import { Hono } from 'hono/tiny'
77
import { app } from '../_backend/public/device/index.ts'
8+
import { sendDiscordAlert } from '../_backend/utils/discord.ts'
9+
import { backgroundTask } from '../_backend/utils/utils.ts'
810

911
const functionName = 'device'
1012
const appGlobal = new Hono<MiddlewareKeyVariables>().basePath(`/${functionName}`)
@@ -23,7 +25,7 @@ appGlobal.all('*', (c) => {
2325
console.log('Not found', c.req.url)
2426
return c.json({ error: 'Not Found' }, 404)
2527
})
26-
appGlobal.onError((e, c) => {
28+
appGlobal.onError(async (e, c) => {
2729
console.log('app onError', e)
2830
c.get('sentry')?.captureException(e)
2931
if (e instanceof HTTPException) {
@@ -33,6 +35,21 @@ appGlobal.onError((e, c) => {
3335
}
3436
return c.json({ status: 'Internal Server Error', response: e.getResponse(), error: JSON.stringify(e), message: e.message }, e.status)
3537
}
38+
await backgroundTask(c as any, sendDiscordAlert(c as any, {
39+
content: `Function: ${functionName}`,
40+
embeds: [
41+
{
42+
title: `Failed to process ${functionName}`,
43+
description: `Function: ${functionName}`,
44+
fields: [
45+
{
46+
name: 'Error',
47+
value: JSON.stringify(e),
48+
},
49+
],
50+
},
51+
],
52+
}))
3653
return c.json({ status: 'Internal Server Error', error: JSON.stringify(e), message: e.message }, 500)
3754
})
3855
Deno.serve(appGlobal.fetch)

supabase/functions/files/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { logger } from 'hono/logger'
55
import { requestId } from 'hono/request-id'
66
import { Hono } from 'hono/tiny'
77
import { app as files } from '../_backend/private/files.ts'
8+
import { sendDiscordAlert } from '../_backend/utils/discord.ts'
9+
import { backgroundTask } from '../_backend/utils/utils.ts'
810

911
const functionName = 'files'
1012
const appGlobal = new Hono<MiddlewareKeyVariables>().basePath(`/${functionName}`)
@@ -25,7 +27,7 @@ appGlobal.all('*', (c) => {
2527
console.log('Not found', c.req.url)
2628
return c.json({ error: 'Not Found' }, 404)
2729
})
28-
appGlobal.onError((e, c) => {
30+
appGlobal.onError(async (e, c) => {
2931
console.log('app onError', e)
3032
c.get('sentry')?.captureException(e)
3133
if (e instanceof HTTPException) {
@@ -35,6 +37,21 @@ appGlobal.onError((e, c) => {
3537
}
3638
return c.json({ status: 'Internal Server Error', response: e.getResponse(), error: JSON.stringify(e), message: e.message }, e.status)
3739
}
40+
await backgroundTask(c as any, sendDiscordAlert(c as any, {
41+
content: `Function: ${functionName}`,
42+
embeds: [
43+
{
44+
title: `Failed to process ${functionName}`,
45+
description: `Function: ${functionName}`,
46+
fields: [
47+
{
48+
name: 'Error',
49+
value: JSON.stringify(e),
50+
},
51+
],
52+
},
53+
],
54+
}))
3855
return c.json({ status: 'Internal Server Error', error: JSON.stringify(e), message: e.message }, 500)
3956
})
4057
Deno.serve(appGlobal.fetch)

0 commit comments

Comments
 (0)