Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.

Commit

Permalink
Sentry Integration (#170)
Browse files Browse the repository at this point in the history
* Basic version of sentry is implemented

* Enhanced continuous reading to show a warning when we couldn't find the next reading point. This will also short circuit after the first warning is shown

* Implemented Sentry. Currently src maps aren't uploading
  • Loading branch information
majora2007 authored May 11, 2021
1 parent dc6d327 commit 4fc7c43
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 166 deletions.
6 changes: 5 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"src/favicon.ico",
"src/assets"
],
"sourceMap": {
"hidden": false,
"scripts": true,
"styles": true
},
"styles": [
"node_modules/ngx-toastr/toastr.css",
"src/styles.scss",
Expand All @@ -47,7 +52,6 @@
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": true,
Expand Down
150 changes: 148 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"@ng-bootstrap/ng-bootstrap": "^9.1.0",
"@ngx-lite/nav-drawer": "^0.4.6",
"@ngx-lite/util": "0.0.0",
"@sentry/angular": "^6.3.6",
"@sentry/integrations": "^6.3.6",
"@types/file-saver": "^2.0.1",
"angular-ng-autocomplete": "^2.0.5",
"bootstrap": "^4.5.0",
Expand Down
6 changes: 4 additions & 2 deletions src/app/_interceptors/error.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
HttpInterceptor
} from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { NavigationExtras, Router } from '@angular/router';
import { Router } from '@angular/router';
import { ToastrService } from 'ngx-toastr';
import { catchError, take } from 'rxjs/operators';
import { AccountService } from '../_services/account.service';
Expand All @@ -20,7 +20,6 @@ export class ErrorInterceptor implements HttpInterceptor {
return next.handle(request).pipe(
catchError(error => {
if (error && error.status !== 200) {
console.error('error:', error);
switch (error.status) {
case 400:
// IF type of array, this comes from signin handler
Expand All @@ -47,6 +46,7 @@ export class ErrorInterceptor implements HttpInterceptor {
}
throw modalStateErrors.flat();
} else {
console.error('error:', error);
if (error.statusText === 'Bad Request') {
this.toastr.error(error.error, error.status);
} else {
Expand All @@ -65,9 +65,11 @@ export class ErrorInterceptor implements HttpInterceptor {
});
break;
case 404:
console.error('error:', error);
this.toastr.error('That url does not exist.');
break;
case 500:
console.error('error:', error);
this.toastr.error('There was an unknown critical error.');
break;
default:
Expand Down
8 changes: 8 additions & 0 deletions src/app/_services/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { map } from 'rxjs/operators';
import { environment } from 'src/environments/environment';
import { Preferences } from '../_models/preferences/preferences';
import { User } from '../_models/user';
import * as Sentry from "@sentry/angular";

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -44,6 +45,13 @@ export class AccountService {
}

localStorage.setItem(this.userKey, JSON.stringify(user));
Sentry.configureScope(scope => {
scope.setUser({
username: user.username
});
});

Sentry.setContext('admin', {'admin': this.hasAdminRole(user)});
this.currentUserSource.next(user);
this.currentUser = user;
}
Expand Down
1 change: 0 additions & 1 deletion src/app/_services/reader.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class ReaderService {
}
for (let c of currentlyReadingVolume.chapters) {
if (c.pagesRead < c.pages) {
console.log('Current chapter is: v' + v.number + ' c' + c.number );
currentlyReadingChapter = c;
break;
}
Expand Down
50 changes: 48 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { APP_INITIALIZER, ErrorHandler, Injectable, NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
Expand All @@ -25,7 +25,37 @@ import { ReviewSeriesModalComponent } from './_modals/review-series-modal/review
import { LazyLoadImageModule} from 'ng-lazyload-image';
import { CarouselModule } from './carousel/carousel.module';
import { NgxSliderModule } from '@angular-slider/ngx-slider';
import { SwiperModule } from 'swiper/angular';

import * as Sentry from "@sentry/angular";
import { environment } from 'src/environments/environment';
import { version } from 'package.json';
import { Router } from '@angular/router';
import { RewriteFrames as RewriteFramesIntegration } from "@sentry/integrations";
import { Dedupe as DedupeIntegration } from "@sentry/integrations";

Sentry.init({
dsn: "https://[email protected]/5757426",
environment: environment.production ? 'prod' : 'dev',
release: version,
integrations: [
new Sentry.Integrations.GlobalHandlers({
onunhandledrejection: true,
onerror: true
}),
new DedupeIntegration(),
new RewriteFramesIntegration()
],
ignoreErrors: [new RegExp(/\/api\/admin/)],
tracesSampleRate: environment.production ? 0 : 1.0,
});

Sentry.configureScope(scope => {
scope.setUser({
username: 'Not authorized'
});
scope.setTag('production', environment.production);
scope.setTag('version', version);
});



Expand Down Expand Up @@ -69,6 +99,22 @@ import { SwiperModule } from 'swiper/angular';
{provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},
//{ provide: LAZYLOAD_IMAGE_HOOKS, useClass: ScrollHooks } // Great, but causes flashing after modals close
{
provide: ErrorHandler,
useValue: Sentry.createErrorHandler({
showDialog: false,
}),
},
{
provide: Sentry.TraceService,
deps: [Router],
},
{
provide: APP_INITIALIZER,
useFactory: () => () => {},
deps: [Sentry.TraceService],
multi: true,
}
],
entryComponents: [],
bootstrap: [AppComponent]
Expand Down
Loading

0 comments on commit 4fc7c43

Please sign in to comment.