Added manual sentry error reporting

This commit is contained in:
Mitchell McCaffrey 2020-10-27 10:26:55 +11:00
parent f096043975
commit d9cd5f78cc
6 changed files with 22 additions and 7 deletions

8
src/helpers/logging.js Normal file
View File

@ -0,0 +1,8 @@
import { captureException } from "@sentry/react";
export function logError(error) {
console.error(error);
if (process.env.NODE_ENV === "production") {
captureException(error);
}
}

View File

@ -1,5 +1,7 @@
import GridSizeModel from "../ml/gridSize/GridSizeModel";
import { logError } from "./logging";
export function getMapDefaultInset(width, height, gridX, gridY) {
// Max the width
const gridScale = width / gridX;
@ -140,7 +142,7 @@ export async function getGridSize(image) {
try {
prediction = await gridSizeML(image, candidates);
} catch (error) {
console.error(error);
logError(error);
}
if (!prediction) {

View File

@ -3,6 +3,7 @@ import { encode, decode } from "@msgpack/msgpack";
import shortid from "shortid";
import blobToBuffer from "../helpers/blobToBuffer";
import { logError } from "../helpers/logging";
// Limit buffer size to 16kb to avoid issues with chrome packet size
// http://viblast.com/blog/2015/2/5/webrtc-data-channel-message-size/
@ -78,7 +79,7 @@ class Connection extends SimplePeer {
}
}
} catch (error) {
console.error(error);
logError(error);
}
}

View File

@ -4,6 +4,7 @@ import { EventEmitter } from "events";
import Connection from "./Connection";
import { omit } from "../helpers/shared";
import { logError } from "../helpers/logging";
/**
* @typedef {object} SessionPeer
@ -112,8 +113,8 @@ class Session extends EventEmitter {
const data = await response.json();
this._iceServers = data.iceServers;
this.socket.emit("join party", partyId, password);
} catch (e) {
console.error("Unable to join party:", e.message);
} catch (error) {
logError(error);
this.emit("disconnected");
}
}
@ -190,6 +191,7 @@ class Session extends EventEmitter {
this.peers[id] = peer;
} catch (error) {
logError(error);
this.emit("error", { error });
}
}

View File

@ -15,6 +15,8 @@ import Footer from "../components/Footer";
import Banner from "../components/Banner";
import LoadingOverlay from "../components/LoadingOverlay";
import { logError } from "../helpers/logging";
const prices = [
{ price: "$5.00", name: "Small", value: 5 },
{ price: "$15.00", name: "Medium", value: 15 },
@ -36,8 +38,9 @@ function Donate() {
setStripe(stripe);
setLoading(false);
})
.catch((err) => {
setError(err.message);
.catch((error) => {
logError(error);
setError(error.message);
setLoading(false);
});
});

View File

@ -49,7 +49,6 @@ function Game() {
const [peerError, setPeerError] = useState(null);
useEffect(() => {
function handlePeerError({ error }) {
console.error(error.code);
if (error.code === "ERR_WEBRTC_SUPPORT") {
setPeerError("WebRTC not supported.");
} else if (error.code === "ERR_CREATE_OFFER") {