Skip to content

Commit

Permalink
Merge pull request #3 from fumeapp/add-rejections
Browse files Browse the repository at this point in the history
✨ add unhandled rejections
  • Loading branch information
acidjazz authored Jan 24, 2025
2 parents bcd5232 + 1c3f0ee commit 96908d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/runtime/care.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ interface ErrorPayload {
hook: string
cause: string
client?: boolean
timestamp: number
os: {
platform: string
arch: string
Expand All @@ -19,6 +18,7 @@ export enum CareHookType {
vueError = 'vue:error',
appError = 'app:error',
nitroError = 'nitro:error',
windowRejection = 'window:unhandledrejection',
}

const validApiKey = (config: Config): boolean => {
Expand All @@ -44,6 +44,7 @@ export const careCheckConfig = (config: Config): boolean => {
}

export const careReport = (type: CareHookType, error: unknown, config: Config) => {
console.log('calling careReport')
sendError(type, error as ErrorPayload, config)
}

Expand All @@ -55,14 +56,13 @@ const sendError = async (hook: string, error: ErrorPayload, config: Config) => {
hook: hook,
cause: error.cause,
client: typeof window !== 'undefined',
timestamp: Math.floor(Date.now() / 1000),
os: {
platform: process.platform,
arch: process.arch,
version: process.version,
},
}
const url = `${config.apiDomain}/api/entry`
const url = `${config.apiDomain}/api/issue`
try {
if (config.verbose) {
log.info(`[fume.care] Error in ${hook} going to ${url}`, payload)
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { defineNuxtPlugin, useRuntimeConfig } from '#app'
export default defineNuxtPlugin((nuxtApp) => {
const config = useRuntimeConfig().public.care as Required<ModuleOptions>
if (careCheckConfig(config)) {
if (import.meta.client || window) {
window.addEventListener('unhandledrejection', event =>
careReport(CareHookType.windowRejection, event.reason, config))
}
nuxtApp.hook('vue:error', (error: unknown, _instance, _info) => careReport(CareHookType.vueError, error, config))
nuxtApp.hook('app:error', (error: unknown) => careReport(CareHookType.appError, error, config))
}
Expand Down

0 comments on commit 96908d4

Please sign in to comment.