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

Add some helper functions for automatic error reporting.

This uses sentry internally, but only sends things to the server when
configured that way.
parent 8f03cd32
No related branches found
No related tags found
No related merge requests found
import './vpu-mini-spinner.js';
import './vpu-spinner.js';
import './vpu-icon.js';
import './vpu-button.js';
\ No newline at end of file
import './vpu-button.js';
import {init, captureMessage, captureException} from './errorreport';
// error reporting
init({debug: false, release: 'vpu-common@0.1'});
captureMessage("test error message");
captureException(new Error('another error'));
setTimeout(() => {
throw new Error("an error");
});
......@@ -8,6 +8,7 @@ switch(environment) {
apiBaseUrl: 'https://mw-dev.tugraz.at',
apiUrlPrefix: '',
keyCloakClientId: 'auth-dev-mw-frontend',
sentryDSN: 'http://0405d811e8d746cca2e70f6eff764570@129.27.166.25:9000/2',
};
break;
......@@ -35,4 +36,4 @@ switch(environment) {
}
export default config;
export default config;
\ No newline at end of file
import * as Sentry from '@sentry/browser';
import env from './env.js';
import environment from 'consts:environment';
/**
* Initializes error reporting.
*
* If a sentry DSN is set we will use sentry, if not we will log to the console.
*
* @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);
let sentryOptions = {debug: actual.debug, environment: environment};
if (actual.release) {
sentryOptions['release'] = actual.release;
}
if (!env.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'] = env.sentryDSN;
}
Sentry.init(sentryOptions);
}
/**
* Log an exception
*
* @param {*} exception
*/
export function captureException(exception) {
Sentry.captureException(exception);
}
/**
* Log a message, returns an internal ID
*
* @param {String} message The message to log
* @param {String} [level=error] The loglevel (error, warning, info, debug)
*/
export function captureMessage(message, level) {
if (!level)
level = 'error';
if (!['error', 'warning', 'info', 'debug'].includes(level))
throw new Error('Invalid log level');
Sentry.captureMessage(message, level);
}
\ No newline at end of file
......@@ -29,9 +29,10 @@
"watch": "rollup -c --watch"
},
"dependencies": {
"@sentry/browser": "^5.6.3",
"bulma": "^0.7.5",
"i18next": "^17.0.11",
"lit-element": "^2.2.1",
"material-design-icons-svg": "^3.0.0",
"bulma": "^0.7.5"
"material-design-icons-svg": "^3.0.0"
}
}
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