Skip to content

Commit

Permalink
Add error logger for failed post
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Mar 20, 2024
1 parent a14cd2d commit 5892eae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/chats/ChatForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useRequestTokenAndSendMessage from '@/hooks/useRequestTokenAndSendMessage
import { showErrorToast } from '@/hooks/useToastError'
import { useConfigContext } from '@/providers/config/ConfigProvider'
import { getPostQuery } from '@/services/api/query'
import { apiInstance } from '@/services/api/utils'
import { useSendOffchainMessage } from '@/services/datahub/posts/mutation'
import {
SendMessageParams,
Expand Down Expand Up @@ -424,6 +425,8 @@ function showErrorSendingMessageToast(
}
}

apiInstance.post('/api/logger', { error: error + '' }).catch(console.error)

showErrorToast(error, title, {
toastConfig: { duration: isRateLimited ? 5000 : Infinity },
getDescription:
Expand Down
16 changes: 16 additions & 0 deletions src/pages/api/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { handlerWrapper } from '@/server/common'
import { z } from 'zod'

export default handlerWrapper({
inputSchema: z.object({
error: z.unknown(),
}),
dataGetter: (req) => req.body,
})({
allowedMethods: ['POST'],
errorLabel: 'logger',
handler: async (data, _, res) => {
console.error('Error logged from logger: ', data.error)
res.json({ success: true, message: 'OK' })
},
})

0 comments on commit 5892eae

Please sign in to comment.