Extra Stat collection (#407)

* Cleaned up error interceptor to avoid sending auth errors (when a 500 occurs) to sentry as auth errors aren't issues.

* Added extra stat collection

* Fixed a bad gitignore which ignored anything in a stats directory
This commit is contained in:
Joseph Milazzo 2021-07-20 11:32:37 -05:00 committed by GitHub
parent b9a06d3586
commit b11bb0e3b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 64 additions and 57 deletions

View file

@ -25,10 +25,6 @@ export class ErrorInterceptor implements HttpInterceptor {
if (error === undefined || error === null) {
return throwError(error);
}
if (!environment.production) {
console.error('error:', error);
}
switch (error.status) {
case 400:
@ -99,12 +95,15 @@ export class ErrorInterceptor implements HttpInterceptor {
}
private handleServerException(error: any) {
console.error('500 error:', error);
const err = error.error;
if (err.hasOwnProperty('message') && err.message.trim() !== '') {
if (err.message != 'User is not authenticated') {
console.log('500 error: ', error);
}
this.toastr.error(err.message);
} else {
this.toastr.error('There was an unknown critical error.');
console.error('500 error:', error);
}
}

View file

@ -7,6 +7,7 @@ export interface ClientInfo {
platformType: string,
kavitaUiVersion: string,
screenResolution: string;
usingDarkTheme: boolean;
collectedAt?: Date;
}

View file

@ -1,7 +1,13 @@
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import * as Bowser from "bowser";
import { take } from "rxjs/operators";
import { environment } from "src/environments/environment";
import { ClientInfo } from "../_models/client-info";
import { ClientInfo } from "../_models/stats/client-info";
import { DetailsVersion } from "../_models/stats/details-version";
import { NavService } from "./nav.service";
import { version } from '../../../package.json';
@Injectable({
providedIn: 'root'
@ -10,9 +16,27 @@ export class StatsService {
baseUrl = environment.apiUrl;
constructor(private httpClient: HttpClient) { }
constructor(private httpClient: HttpClient, private navService: NavService) { }
public sendClientInfo(clientInfo: ClientInfo) {
return this.httpClient.post(this.baseUrl + 'stats/client-info', clientInfo);
public async sendClientInfo() {
const data = await this.getInfo();
this.httpClient.post(this.baseUrl + 'stats/client-info', data);
}
private async getInfo(): Promise<ClientInfo> {
const screenResolution = `${window.screen.width} x ${window.screen.height}`;
const browser = Bowser.getParser(window.navigator.userAgent);
const usingDarkTheme = await this.navService.darkMode$.pipe(take(1)).toPromise();
return {
os: browser.getOS() as DetailsVersion,
browser: browser.getBrowser() as DetailsVersion,
platformType: browser.getPlatformType(),
kavitaUiVersion: version,
screenResolution,
usingDarkTheme
};
}
}

View file

@ -5,7 +5,6 @@ import { take } from 'rxjs/operators';
import { MemberService } from '../_services/member.service';
import { AccountService } from '../_services/account.service';
import { StatsService } from '../_services/stats.service';
import * as ClientUtils from "../shared/utils/clientUtils";
@Component({
selector: 'app-home',
@ -35,9 +34,7 @@ export class HomeComponent implements OnInit {
this.accountService.currentUser$.pipe(take(1)).subscribe(user => {
this.statsService.sendClientInfo(ClientUtils.getClientInfo())
.pipe(take(1))
.subscribe(resp => {/* No Operation */});
this.statsService.sendClientInfo();
if (user) {
this.router.navigateByUrl('/library');

View file

@ -8,6 +8,7 @@
.poster {
width: 100%;
max-height: 230px;
}
.rating-star {

View file

@ -1,21 +0,0 @@
import * as Bowser from "bowser";
import { version } from '../../../../package.json';
import { ClientInfo } from "src/app/_models/client-info";
import { DetailsVersion } from "src/app/_models/details-version";
const getClientInfo = (): ClientInfo => {
const screenResolution = `${window.screen.width} x ${window.screen.height}`;
const browser = Bowser.getParser(window.navigator.userAgent);
return {
os: browser.getOS() as DetailsVersion,
browser: browser.getBrowser() as DetailsVersion,
platformType: browser.getPlatformType(),
kavitaUiVersion: version,
screenResolution
};
}
export { getClientInfo };