-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added error tracking / logging (#220)
- Loading branch information
Showing
6 changed files
with
87 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use client"; | ||
|
||
import { log } from "@logtail/next"; | ||
import { useEffect } from "react"; | ||
|
||
export default function Logger() { | ||
useEffect(() => { | ||
function logError(event: ErrorEvent) { | ||
console.log("ERROR DETECTED"); | ||
log.error(event.message, { | ||
column: event.colno, | ||
line: event.lineno, | ||
url: event.filename, | ||
}); | ||
} | ||
function logUnhandledRejection(event: PromiseRejectionEvent) { | ||
console.log("ERROR DETECTED"); | ||
log.error("Unhandled Promise Rejection", { | ||
reason: event.reason as string, | ||
}); | ||
} | ||
|
||
window.addEventListener("error", logError); | ||
window.addEventListener("unhandledrejection", logUnhandledRejection); | ||
return () => { | ||
document.removeEventListener("error", logError); | ||
}; | ||
}, []); | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
import { log } from "@logtail/next"; | ||
import { withLogtail } from "@logtail/next"; | ||
import { createNextApiHandler } from "@trpc/server/adapters/next"; | ||
import { env } from "~/../env.mjs"; | ||
|
||
import { appRouter } from "~/server/api/root"; | ||
import { createTRPCContext } from "~/server/api/trpc"; | ||
|
||
// export API handler | ||
export default createNextApiHandler({ | ||
createContext: createTRPCContext, | ||
onError: | ||
env.NODE_ENV === "development" | ||
? ({ error, path }) => { | ||
console.error( | ||
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}` | ||
); | ||
} | ||
: undefined, | ||
router: appRouter, | ||
}); | ||
export default withLogtail( | ||
createNextApiHandler({ | ||
createContext: createTRPCContext, | ||
onError: | ||
env.NODE_ENV === "development" | ||
? ({ error, path }) => { | ||
console.error( | ||
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}` | ||
); | ||
} | ||
: ({ error, path }) => { | ||
log.error( | ||
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}` | ||
); | ||
if (error.stack !== undefined) { | ||
log.error(error.stack); | ||
} | ||
}, | ||
router: appRouter, | ||
}) | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.