Skip to content
Snippets Groups Projects
Commit 3ad80f20 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Add a wrapper for Sentry.showReportDialog()

parent 8e03da0d
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,9 @@ import * as Sentry from '@sentry/browser';
import env from './env.js';
import environment from 'consts:environment';
let _isInitialized = false
let _canReportEvent = false;
/**
* Initializes error reporting.
*
......@@ -16,6 +19,9 @@ export function init(options) {
};
let actual = Object.assign({}, defaults, options);
if (_isInitialized)
throw new Error("Already initialized");
let sentryOptions = {debug: actual.debug, environment: environment};
if (actual.release) {
......@@ -36,9 +42,32 @@ export function init(options) {
};
} else {
sentryOptions['dsn'] = env.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())
return;
Sentry.showReportDialog();
}
/**
......@@ -47,6 +76,8 @@ export function init(options) {
* @param {*} exception
*/
export function captureException(exception) {
if (!_isInitialized)
throw new Error("Not initialized");
Sentry.captureException(exception);
}
......@@ -57,6 +88,8 @@ export function captureException(exception) {
* @param {String} [level=error] The loglevel (error, warning, info, debug)
*/
export function captureMessage(message, level) {
if (!_isInitialized)
throw new Error("Not initialized");
if (!level)
level = 'error';
if (!['error', 'warning', 'info', 'debug'].includes(level))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment