feat : add sentry
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
LichessGame,
|
||||
LichessResponse,
|
||||
} from "@/types/lichess";
|
||||
import { logErrorToSentry } from "./sentry";
|
||||
|
||||
export const getLichessEval = async (
|
||||
fen: string,
|
||||
@@ -52,7 +53,8 @@ export const getLichessEval = async (
|
||||
lines: linesToKeep,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
const err = error instanceof Error ? error : new Error("Unknown error");
|
||||
logErrorToSentry(err, { fen, multiPv });
|
||||
return {
|
||||
bestMove: "",
|
||||
lines: [],
|
||||
|
||||
17
src/lib/sentry.ts
Normal file
17
src/lib/sentry.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as Sentry from "@sentry/nextjs";
|
||||
|
||||
export const isSentryEnabled = () =>
|
||||
!!process.env.NEXT_PUBLIC_SENTRY_DSN && Sentry.isInitialized();
|
||||
|
||||
export const logErrorToSentry = (
|
||||
error: Error,
|
||||
context?: Record<string, unknown>
|
||||
) => {
|
||||
if (isSentryEnabled()) {
|
||||
Sentry.captureException(error, {
|
||||
extra: context,
|
||||
});
|
||||
} else {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
Typography,
|
||||
Grid2 as Grid,
|
||||
} from "@mui/material";
|
||||
import { setContext as setSentryContext } from "@sentry/react";
|
||||
import { Chess } from "chess.js";
|
||||
import { useState } from "react";
|
||||
import GamePgnInput from "./gamePgnInput";
|
||||
@@ -43,6 +44,7 @@ export default function NewGameDialog({ open, onClose, setGame }: Props) {
|
||||
|
||||
try {
|
||||
const gameToAdd = getGameFromPgn(pgn);
|
||||
setSentryContext("loadedGame", { pgn });
|
||||
|
||||
if (setGame) {
|
||||
setGame(gameToAdd);
|
||||
|
||||
Reference in New Issue
Block a user