@gibraltarsoftware/loupe-angular
Version:
Loupe Agent for Angular
219 lines (210 loc) • 10.2 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, Component, ErrorHandler, NgModule } from '@angular/core';
import { LoupeAgent } from '@gibraltarsoftware/loupe-typescript/dist/loupe.agent';
import { HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
function getWindow() { return window; }
function getloupelibService() { return new LoupeService(getWindow()); }
class LoupeService {
constructor(window) {
this.window = null;
if (this.window) {
this.window = getWindow();
}
else {
this.window = window;
}
this.loupe = new LoupeAgent(this.window, this.window.document);
}
setLogServer(origin) {
this.loupe.setLogServer(origin);
}
addHeader(header) {
this.loupe.addHeader(header);
}
flushToServer() {
this.loupe.flushToServer();
}
information(category, caption, description, parameters, exception, details, methodSourceInfo) {
this.loupe.information(category, caption, description, parameters, exception, details, methodSourceInfo);
}
verbose(category, caption, description, parameters, exception, details, methodSourceInfo) {
this.loupe.verbose(category, caption, description, parameters, exception, details, methodSourceInfo);
}
warning(category, caption, description, parameters, exception, details, methodSourceInfo) {
this.loupe.warning(category, caption, description, parameters, exception, details, methodSourceInfo);
}
error(category, caption, description, parameters, exception, details, methodSourceInfo) {
this.loupe.error(category, caption, description, parameters, exception, details, methodSourceInfo);
}
critical(category, caption, description, parameters, exception, details, methodSourceInfo) {
this.loupe.critical(category, caption, description, parameters, exception, details, methodSourceInfo);
}
recordException(exception, details, category) {
this.loupe.recordException(exception, details, category);
}
}
LoupeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeService, deps: "invalid", target: i0.ɵɵFactoryTarget.Injectable });
LoupeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeService, providedIn: 'root', useFactory: getloupelibService });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root',
useFactory: getloupelibService
}]
}], ctorParameters: function () { return [{ type: undefined }]; } });
class LoupeAngularComponent {
constructor() { }
ngOnInit() {
}
}
LoupeAngularComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeAngularComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
LoupeAngularComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.9", type: LoupeAngularComponent, selector: "lib-loupe-angular", ngImport: i0, template: `
<p>
loupe-angular works!
</p>
`, isInline: true });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeAngularComponent, decorators: [{
type: Component,
args: [{
selector: 'lib-loupe-angular',
template: `
<p>
loupe-angular works!
</p>
`,
styles: []
}]
}], ctorParameters: function () { return []; } });
// http interceptor to automatically add the Loupe Session and Agent IDs to HTTP requests, to aid in request correlation
class LoupeHeaderHttpConfigInterceptor {
constructor(loupeService) {
this.loupeService = loupeService;
this.loupeAgentSessionIdHeader = loupeService.loupe.loupeAgentSessionIdHeader;
this.loupeSessionIdHeader = loupeService.loupe.loupeSessionIdHeader;
}
intercept(request, next) {
// add the loupe headers to the request
request = request.clone({
headers: request.headers.set(this.loupeAgentSessionIdHeader, this.loupeService.loupe.agentSessionId)
});
request = request.clone({
headers: request.headers.set(this.loupeSessionIdHeader, this.loupeService.loupe.sessionId)
});
return next.handle(request);
}
}
LoupeHeaderHttpConfigInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeHeaderHttpConfigInterceptor, deps: [{ token: LoupeService }], target: i0.ɵɵFactoryTarget.Injectable });
LoupeHeaderHttpConfigInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeHeaderHttpConfigInterceptor });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeHeaderHttpConfigInterceptor, decorators: [{
type: Injectable
}], ctorParameters: function () { return [{ type: LoupeService }]; } });
// error handler to automatically log uncaught errors to Loupe
class LoupeErrorHandler extends ErrorHandler {
constructor(loupe) {
super();
this.loupe = loupe;
}
handleError(error) {
super.handleError(error);
// different error types have different properties
if (error instanceof HttpErrorResponse) {
this.recordHttpError(error);
}
else if (error instanceof ErrorEvent) {
this.recordErrorEvent(error);
}
else {
this.recordError(error);
}
}
recordHttpError(error) {
const details = {
name: error.name,
status: error.status,
statusText: error.statusText,
url: error.url,
error: error.error
};
// The http error response doesn't gve us a stack, so create one
const err = new Error(error.message);
const ex = {
name: error.name,
caption: error.name,
description: error.message,
message: err.stack
};
this.loupe.recordException(ex, details, error.name);
}
recordError(error) {
// check to see if there's a stack
const errorSource = error.stack || error.message;
const parts = errorSource.split('\n');
let url = "";
if (parts.length > 2) {
// see if we have a url
const firstStackLine = parts[2];
const httpStart = firstStackLine.indexOf('http');
if (httpStart > -1) {
const httpLength = firstStackLine.length - httpStart - 1;
url = firstStackLine.substr(httpStart, httpLength);
}
}
const ex = {
name: error.name,
caption: parts[1],
description: parts[0],
url: url,
message: errorSource
};
const details = null;
this.loupe.recordException(ex, details, 'Angular.Exception');
}
recordErrorEvent(error) {
const details = {
line: error.lineno,
column: error.colno,
url: error.filename
};
this.loupe.recordException(error, details, 'Angular.Exception.Event');
}
}
LoupeErrorHandler.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeErrorHandler, deps: [{ token: LoupeService }], target: i0.ɵɵFactoryTarget.Injectable });
LoupeErrorHandler.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeErrorHandler, providedIn: 'root' });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeErrorHandler, decorators: [{
type: Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: function () { return [{ type: LoupeService }]; } });
class LoupeAngularModule {
}
LoupeAngularModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeAngularModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
LoupeAngularModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeAngularModule, declarations: [LoupeAngularComponent], exports: [LoupeAngularComponent] });
LoupeAngularModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeAngularModule, providers: [
{ provide: ErrorHandler, useClass: LoupeErrorHandler },
{ provide: HTTP_INTERCEPTORS, useClass: LoupeHeaderHttpConfigInterceptor, multi: true }
], imports: [[]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.9", ngImport: i0, type: LoupeAngularModule, decorators: [{
type: NgModule,
args: [{
declarations: [
LoupeAngularComponent
],
imports: [],
exports: [
LoupeAngularComponent
],
providers: [
{ provide: ErrorHandler, useClass: LoupeErrorHandler },
{ provide: HTTP_INTERCEPTORS, useClass: LoupeHeaderHttpConfigInterceptor, multi: true }
]
}]
}] });
/*
* Public API Surface of loupe-angular
*/
/**
* Generated bundle index. Do not edit.
*/
export { LoupeAngularComponent, LoupeAngularModule, LoupeErrorHandler, LoupeHeaderHttpConfigInterceptor, LoupeService, getWindow, getloupelibService };
//# sourceMappingURL=gibraltarsoftware-loupe-angular.js.map