]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Log frontend errors in backend 22285/head
authorRicardo Marques <rimarques@suse.com>
Wed, 23 May 2018 10:09:23 +0000 (11:09 +0100)
committerRicardo Marques <rimarques@suse.com>
Wed, 30 May 2018 08:17:37 +0000 (09:17 +0100)
Signed-off-by: Ricardo Marques <rimarques@suse.com>
src/pybind/mgr/dashboard/controllers/logging.py [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/app.module.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/api.module.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/logging.service.ts [new file with mode: 0644]
src/pybind/mgr/dashboard/frontend/src/app/shared/services/js-error-handler.service.ts [new file with mode: 0644]

diff --git a/src/pybind/mgr/dashboard/controllers/logging.py b/src/pybind/mgr/dashboard/controllers/logging.py
new file mode 100644 (file)
index 0000000..f92fc2b
--- /dev/null
@@ -0,0 +1,10 @@
+from . import UiApiController, BaseController, Endpoint
+from .. import logger
+
+
+@UiApiController('/logging')
+class Logging(BaseController):
+
+    @Endpoint('POST', path='js-error')
+    def jsError(self, url, message, stack):
+        logger.error('frontend error (%s): %s\n %s\n', url, message, stack)
index 4c5974ec304f2cb80b106a0685ab10f8d6e25728..a13d50c8b57acec6f52a4c6158a84e73b2ca5e21 100644 (file)
@@ -1,5 +1,5 @@
 import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
-import { NgModule } from '@angular/core';
+import { ErrorHandler, NgModule } from '@angular/core';
 import { BrowserModule } from '@angular/platform-browser';
 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
 
@@ -11,6 +11,7 @@ import { AppComponent } from './app.component';
 import { CephModule } from './ceph/ceph.module';
 import { CoreModule } from './core/core.module';
 import { ApiInterceptorService } from './shared/services/api-interceptor.service';
+import { JsErrorHandler } from './shared/services/js-error-handler.service';
 import { SharedModule } from './shared/shared.module';
 
 export class CustomOption extends ToastOptions {
@@ -39,6 +40,10 @@ export class CustomOption extends ToastOptions {
   ],
   exports: [SharedModule],
   providers: [
+    {
+      provide: ErrorHandler,
+      useClass: JsErrorHandler,
+    },
     {
       provide: HTTP_INTERCEPTORS,
       useClass: ApiInterceptorService,
index 4e63dc17692bce62633df80e852d9420ff58f5ff..8a8fd64da5caa3575ae805682ecfe58fc107abaf 100644 (file)
@@ -6,6 +6,7 @@ import { CephfsService } from './cephfs.service';
 import { ConfigurationService } from './configuration.service';
 import { DashboardService } from './dashboard.service';
 import { HostService } from './host.service';
+import { LoggingService } from './logging.service';
 import { MonitorService } from './monitor.service';
 import { OsdService } from './osd.service';
 import { PerformanceCounterService } from './performance-counter.service';
@@ -35,6 +36,7 @@ import { TcmuIscsiService } from './tcmu-iscsi.service';
     RgwDaemonService,
     RgwUserService,
     PerformanceCounterService,
+    LoggingService,
     TcmuIscsiService
   ]
 })
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/logging.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/logging.service.ts
new file mode 100644 (file)
index 0000000..746df54
--- /dev/null
@@ -0,0 +1,19 @@
+import { HttpClient } from '@angular/common/http';
+import { Injectable } from '@angular/core';
+
+@Injectable()
+export class LoggingService {
+
+  constructor(private http: HttpClient) {
+  }
+
+  jsError(url, message, stack) {
+    const request = {
+      url: url,
+      message: message,
+      stack: stack
+    };
+    return this.http.post('ui-api/logging/js-error', request);
+  }
+
+}
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/js-error-handler.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/js-error-handler.service.ts
new file mode 100644 (file)
index 0000000..c906cad
--- /dev/null
@@ -0,0 +1,18 @@
+import { ErrorHandler, Injectable, Injector } from '@angular/core';
+import { LoggingService } from '../api/logging.service';
+
+@Injectable()
+export class JsErrorHandler implements ErrorHandler {
+
+  constructor(private injector: Injector) { }
+
+  handleError(error) {
+    const loggingService = this.injector.get(LoggingService);
+    const url = window.location.href;
+    const message = error && error.message;
+    const stack = error && error.stack;
+    loggingService.jsError(url, message, stack).subscribe();
+    throw error;
+  }
+
+}