Send version to Sentry

This commit is contained in:
ziajka 2018-06-27 12:34:15 +02:00
parent 957b93ec41
commit 0435fcec89
5 changed files with 19 additions and 18 deletions

View File

@ -79,13 +79,16 @@ import { RavenErrorHandler } from "./raven-error-handler";
import { LocalServerComponent } from './components/local-server/local-server.component';
import { ProgressComponent } from './common/progress/progress.component';
import { ProgressService } from "./common/progress/progress.service";
import { version } from "./version";
Raven
.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726')
.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', {
release: version
})
.install();
@NgModule({
declarations: [
AppComponent,

View File

@ -64,6 +64,8 @@ export class ProjectsComponent implements OnInit {
.subscribe((projects: Project[]) => {
this.projectDatabase.addProjects(projects);
});
}
delete(project: Project) {

View File

@ -1,8 +1,6 @@
import { TestBed } from '@angular/core/testing';
import { PersistenceService } from "angular-persistence";
import * as Raven from 'raven-js';
import { SettingsService } from "./services/settings.service";
import { RavenErrorHandler } from "./raven-error-handler";
import { environment } from "../environments/environment";
@ -32,17 +30,12 @@ describe('RavenErrorHandler', () => {
it('should handle error', () => {
settingsService.set('crash_reports', true);
const error = new Error("My error");
const captureException = spyOn(Raven, 'captureException');
environment.production = true;
handler.handleError(error);
expect(captureException).toHaveBeenCalledWith(error);
expect(handler.shouldSend()).toBeTruthy()
});
it('should not handle when not in production', () => {
const captureException = spyOn(Raven, 'captureException');
environment.production = false;
handler.handleError(new Error("My error"));
expect(captureException).not.toHaveBeenCalled();
it('should not handle when crash reports are disabled', () => {
settingsService.set('crash_reports', false);
expect(handler.shouldSend()).toBeFalsy();
});
});

View File

@ -10,11 +10,13 @@ export class RavenErrorHandler implements ErrorHandler {
constructor(@Inject(Injector) private injector: Injector) {}
handleError(err: any): void {
const settingsService: SettingsService = this.injector.get(SettingsService);
console.error(err.originalError || err);
Raven.setShouldSendCallback(this.shouldSend);
if (environment.production && settingsService.get('crash_reports')) {
Raven.captureException(err.originalError || err);
}
console.error(err.originalError || err);
}
shouldSend() {
const settingsService: SettingsService = this.injector.get(SettingsService);
return environment.production && settingsService.get('crash_reports');
}
}

1
src/app/version.ts Normal file
View File

@ -0,0 +1 @@
export const version = require('../../package.json').version;