Created
November 3, 2017 12:30
-
-
Save unlabeled/d351cc32b646733b1a6388e1d7a50fcd to your computer and use it in GitHub Desktop.
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
import Raven from "raven-js" | |
import { sentry, release } from "../../config" | |
import Api from "utils/api" | |
const immediately = false | |
const errors = [] | |
/* eslint-disable */ | |
const dev = Boolean(__DEV__) | |
/* eslint-enable */ | |
/** | |
* Handle errors with sentry | |
*/ | |
export const handleErrors = function() { | |
if (!dev && sentry) { | |
Raven.config(sentry, { release }).install() | |
} | |
} | |
/** | |
* Set user details for sentry | |
*/ | |
export const setUserContext = function(user) { | |
Raven.setUserContext(user) | |
} | |
/** | |
* Send errors | |
*/ | |
export const sendError = function(error, errorInfo) { | |
if (!dev && sentry) { | |
errors.push({ error, extra: errorInfo }) | |
sendAfterAllApiRequests() | |
} | |
} | |
/** | |
* Delayed sending | |
* TODO: Remove when we will have localStorage for users | |
*/ | |
function sendAfterAllApiRequests() { | |
if (errors.length) { | |
if (!immediately && Api.pending.size !== 0) { | |
setTimeout(sendAfterAllApiRequests, 100) | |
} else { | |
const error = errors.shift() | |
sendImmediately(error) | |
sendAfterAllApiRequests() | |
} | |
} | |
} | |
/** | |
* Send error immediately | |
*/ | |
function sendImmediately({ error, extra }) { | |
Raven.captureException(error, { extra }) | |
} | |
/** | |
* Delayed sending | |
* TODO: Remove when we will have localStorage for users | |
*/ | |
function sendAfterAllApiRequests() { | |
if (errors.length) { | |
if (!immediately && Api.pending.size !== 0) { | |
setTimeout(sendAfterAllApiRequests, 100) | |
} else { | |
const error = errors.shift() | |
sendImmediately(error) | |
sendAfterAllApiRequests() | |
} | |
} | |
} | |
/** | |
* Send error immediately | |
*/ | |
function sendImmediately({ error, extra }) { | |
Raven.captureException(error, { extra }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment