diff --git a/.gitignore b/.gitignore index 14fe5b7..4c55524 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /dist /tmp /out-tsc +/tests # Only exists if Bazel was run /bazel-out diff --git a/docs/compodoc/interceptors/ConnectionInterceptor.html b/docs/compodoc/interceptors/ConnectionInterceptor.html new file mode 100644 index 0000000..ec12b46 --- /dev/null +++ b/docs/compodoc/interceptors/ConnectionInterceptor.html @@ -0,0 +1,371 @@ + + +
+ + ++
+ src/app/_interceptors/connection.interceptor.ts
+
+
+
Intercepts and handles of events from outgoing HTTP request.
+ + + + +
+ Methods+ |
+
+
|
+
+constructor(loggingService: LoggingService)
+ |
+ ||||||||
+ + | +||||||||
+ Initialization of the connection interceptor. +
+ Parameters :
+
+
|
+
+ + + + intercept + + + + | +||||||||||||
+intercept(request: HttpRequest
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Intercepts HTTP requests. +
+ Parameters :
+
+
+
+
+ Returns :
+ Observable<HttpEvent<unknown>>
+
+
+
+ The forwarded request. + + |
+
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
+import { Injectable } from '@angular/core';
+
+// Third party imports
+import { Observable } from 'rxjs';
+
+// Application imports
+import { LoggingService } from '@app/_services/logging.service';
+import { checkOnlineStatus } from '@app/_helpers';
+
+/** Intercepts and handles of events from outgoing HTTP request. */
+@Injectable()
+export class ConnectionInterceptor implements HttpInterceptor {
+ /**
+ * Initialization of the connection interceptor.
+ *
+ * @param loggingService - A service that provides logging capabilities.
+ */
+ constructor(private loggingService: LoggingService) {}
+
+ /**
+ * Intercepts HTTP requests.
+ *
+ * @param request - An outgoing HTTP request with an optional typed body.
+ * @param next - The next HTTP handler or the outgoing request dispatcher.
+ * @returns The forwarded request.
+ */
+ intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
+ checkOnlineStatus().then((online) => {
+ if (!online) {
+ this.loggingService.sendErrorLevelMessage('No internet connection on device!', this, {
+ error: `NetworkError when attempting to fetch resource ${request.url}.`,
+ });
+ return;
+ } else {
+ return next.handle(request);
+ }
+ });
+ return next.handle(request);
+ }
+}
+
+ Initialization of the connection interceptor.
+A service that provides logging capabilities.
+Intercepts HTTP requests.
+An outgoing HTTP request with an optional typed body.
+The next HTTP handler or the outgoing request dispatcher.
+The forwarded request.
+Generated using TypeDoc
+Generated using TypeDoc
+Generated using TypeDoc
+
Intercepts and handles of events from outgoing HTTP request.
+