Select Git revision
-
Reiter, Christoph authored
We now expect the users to pass the right config to vpu-auth. Only the API endpoint config remains which we haven't figured out how to deal with in all cases.
Reiter, Christoph authoredWe now expect the users to pass the right config to vpu-auth. Only the API endpoint config remains which we haven't figured out how to deal with in all cases.
errorreport.js 2.47 KiB
import * as Sentry from '@sentry/browser';
import environment from 'consts:environment';
let _isInitialized = false;
let _canReportEvent = false;
let sentryDSN = '';
/**
* Initializes error reporting.
*
* If a sentry DSN is set we will use sentry, if not we will log to the console.
*
* @param {object} [options]
* @param {boolean} [options.debug=false] Enable debug output
* @param {string} [options.release] The project release
*/
export function init(options) {
let defaults = {
debug: false,
};
let actual = Object.assign({}, defaults, options);
if (_isInitialized)
throw new Error("Already initialized");
let sentryOptions = {debug: actual.debug, environment: environment};
if (actual.release) {
sentryOptions['release'] = actual.release;
}
if (!sentryDSN) {
if (options.debug)
console.log("No sentry DSN set, sentry disabled");
// In case we don't have a sentry config, we still use sentry, but print
// all events into the console don't send them to the server.
// XXX: Dummy DSN needed to make init() work.
sentryOptions['dsn'] = 'http://12345@dummy.dummy/42';
sentryOptions['beforeSend'] = (event, hint) => {
console.error('ERR-REPORT:', hint.originalException || hint.syntheticException);
return null;
};
} else {
sentryOptions['dsn'] = sentryDSN;
_canReportEvent = true;
}
Sentry.init(sentryOptions);
_isInitialized = true;
}
/**
* Whether showReportDialog() will work.
*/
export function canReportEvent() {
if (!_isInitialized)
throw new Error("Not initialized");
return _canReportEvent;
}
/**
* Show a report dialog for user error feedback.
*
* Call canReportEvent() first to see if this will do anything.
*/
export function showReportDialog() {
if (!canReportEvent())