@messaia/cdk 18.1.0 → 18.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,7 +52,7 @@ import * as i1$1 from '@angular/platform-browser';
52
52
  import { Title } from '@angular/platform-browser';
53
53
  import { __decorate, __metadata } from 'tslib';
54
54
  import 'reflect-metadata';
55
- import { Subject, filter, BehaviorSubject, of, map as map$1, fromEvent, distinctUntilChanged, debounceTime, merge as merge$1, tap, Observable, takeUntil as takeUntil$1 } from 'rxjs';
55
+ import { Subject, filter, BehaviorSubject, throwError, of, map as map$1, fromEvent, distinctUntilChanged, debounceTime, merge as merge$1, tap, Observable, takeUntil as takeUntil$1 } from 'rxjs';
56
56
  import { catchError, map, debounceTime as debounceTime$1, distinctUntilChanged as distinctUntilChanged$1, skip, switchMap, takeUntil, tap as tap$1, finalize } from 'rxjs/operators';
57
57
  import * as i3$1 from '@angular/cdk/scrolling';
58
58
  import { ScrollingModule } from '@angular/cdk/scrolling';
@@ -4203,16 +4203,22 @@ class GenericService {
4203
4203
  return "";
4204
4204
  }
4205
4205
  /**
4206
- * Returns a function that handles Http operation failures.
4207
- * This error handler lets the app continue to run as if no error occurred.
4208
- * @param operation - name of the operation that failed
4206
+ * Handles an HTTP operation that failed.
4207
+ * Allows the application to continue by throwing a parsed error.
4208
+ *
4209
+ * @template T The type of the observable result.
4210
+ * @param operation The name of the operation that failed. Defaults to 'operation'.
4211
+ * @param result An optional value to return as the observable result.
4212
+ * @returns A function that processes the error and returns an observable.
4209
4213
  */
4210
- handleError(operation = 'operation') {
4211
- return (error) => {
4212
- console.log(error);
4214
+ handleError(operation = 'operation', result) {
4215
+ return (error) => throwError(() => {
4216
+ if (error.error instanceof ArrayBuffer) {
4217
+ return JSON.parse(new TextDecoder().decode(new Uint8Array(error.error)));
4218
+ }
4213
4219
  const message = (error.error instanceof ErrorEvent) ? error.error.message : `server returned code ${error.status} with body "${error.error}"`;
4214
- throw new Error(`${operation} failed: ${message}`);
4215
- };
4220
+ return `${operation} failed: ${message}`;
4221
+ });
4216
4222
  }
4217
4223
  /**
4218
4224
  * Return distinct message for sent, upload progress, & response events
@@ -23330,55 +23336,56 @@ class BaseInterceptor {
23330
23336
  this.snackBar = snackBar;
23331
23337
  }
23332
23338
  /**
23333
- * Intercept an outgoing `HttpRequest` and optionally transform it or the
23339
+ * Intercepts an outgoing `HttpRequest` and optionally transforms it or the
23334
23340
  * response.
23335
23341
  *
23336
23342
  * Typically an interceptor will transform the outgoing request before returning
23337
- * `next.handle(transformedReq)`. An interceptor may choose to transform the
23338
- * response event stream as well, by applying additional Rx operators on the stream
23339
- * returned by `next.handle()`.
23343
+ * `next.handle(transformedReq)`. An interceptor may also choose to transform the
23344
+ * response event stream by applying additional Rx operators.
23340
23345
  *
23341
- * More rarely, an interceptor may choose to completely handle the request itself,
23342
- * and compose a new event stream instead of invoking `next.handle()`. This is
23343
- * acceptable behavior, but keep in mind further interceptors will be skipped entirely.
23346
+ * In rare cases, an interceptor may completely handle the request itself,
23347
+ * creating a new event stream and bypassing `next.handle()`. This is allowed,
23348
+ * but it means that other interceptors will not be triggered.
23344
23349
  *
23345
- * It is also rare but valid for an interceptor to return multiple responses on the
23346
- * event stream for a single request.
23350
+ * It's also possible, though rare, for an interceptor to return multiple responses
23351
+ * on the event stream for a single request.
23347
23352
  */
23348
23353
  intercept(req, next) {
23349
- /* Clone the request and set the base url */
23354
+ /* Clone the request and set the base URL if it's not already an absolute URL */
23350
23355
  const authReq = req.clone({
23351
- url: req.url.startsWith('http') || req.url.startsWith('./assets') ? req.url : `${this.appSetting.apiUrl}${req.url}`,
23356
+ /* Check if the URL is already absolute or starts with './assets' */
23357
+ url: req.url.startsWith('http') || req.url.startsWith('./assets')
23358
+ ? req.url : `${this.appSetting.apiUrl}${req.url}`,
23359
+ /* Add a custom header for GET requests */
23352
23360
  headers: req.method == 'GET' ? req.headers.set('CheckIn', 'Yes') : req.headers
23353
23361
  });
23354
- /* Send cloned request with header to the next handler */
23362
+ /* Send the cloned request with added headers to the next handler in the chain */
23355
23363
  return next.handle(authReq).pipe(tap$1(
23356
- /* Succeeds when there is a response; ignore other events */
23364
+ /* Handle the response */
23357
23365
  event => {
23358
23366
  if (event instanceof HttpResponse) {
23367
+ /* Check for specific headers in the response */
23359
23368
  if (req.headers.get('Show-Message')) {
23360
- /* Show a success message for POST requests */
23369
+ /* Show success messages for different types of requests */
23361
23370
  if (req.method == 'POST') {
23362
23371
  this.snackBar.open($localize `:@@snackbar.send.success:Data sent successfully.`, undefined, {
23363
23372
  duration: 3000,
23364
23373
  panelClass: ['primary']
23365
23374
  });
23366
23375
  }
23367
- /* Show a success message for PUT or PATCH requests */
23368
23376
  if (['PUT', 'PATCH'].indexOf(req.method) >= 0) {
23369
23377
  this.snackBar.open($localize `:@@snackbar.update.success:Changes saved successfully.`, undefined, {
23370
23378
  duration: 3000,
23371
23379
  panelClass: ['primary']
23372
23380
  });
23373
23381
  }
23374
- /* Show a success message for PUT or PATCH requests */
23375
23382
  if (['DELETE'].indexOf(req.method) >= 0) {
23376
23383
  this.snackBar.open($localize `:@@snackbar.delete.success:Record(s) deleted successfully.`, undefined, {
23377
23384
  duration: 3000,
23378
23385
  panelClass: ['primary']
23379
23386
  });
23380
23387
  }
23381
- /* Show warnings from headers, if any */
23388
+ /* Show warnings from response headers if available */
23382
23389
  var warning = event.headers.get("Warning");
23383
23390
  if (warning) {
23384
23391
  this.snackBar.open(warning, "OK", { duration: 6000, panelClass: ['warn'] });
@@ -23386,58 +23393,85 @@ class BaseInterceptor {
23386
23393
  }
23387
23394
  }
23388
23395
  },
23389
- /* Operation failed; error is an HttpErrorResponse */
23396
+ /* Handle errors */
23390
23397
  error => {
23391
- /* Status: 400 - Bad Request (i.e. validation errors) */
23398
+ /* Handle validation errors for status code 400 (Bad Request) */
23392
23399
  if (error.status == 400) {
23393
23400
  let message = this.parseErrors(error.error);
23394
23401
  if (message) {
23395
23402
  this.snackBar.open(message, "OK", { duration: 8000, panelClass: ['error'] });
23396
23403
  }
23397
23404
  }
23398
- /* Status: 403 - Not permitted */
23405
+ /* Handle permission errors for status code 403 (Forbidden) */
23399
23406
  if (error.status == 403) {
23400
23407
  this.snackBar.open($localize `:@@snackbar.error.not-allowed:You are not allowed to perform this request.`, undefined, {
23401
23408
  duration: 6000,
23402
23409
  panelClass: ['error']
23403
23410
  });
23404
23411
  }
23405
- /* Status: 404 - Bad request, show some error messages */
23412
+ /* Handle not found errors for status code 404 (Not Found) */
23406
23413
  if (error.status == 404) {
23407
23414
  this.snackBar.open($localize `:@@snackbar.error.not-found:The resource could not be found.`, undefined, {
23408
23415
  duration: 6000,
23409
23416
  panelClass: ['error']
23410
23417
  });
23411
23418
  }
23412
- /* Custom error message */
23419
+ /* Handle custom error message for status code 452 */
23413
23420
  if (error.status == 452) {
23414
23421
  this.snackBar.open(error.text(), undefined, { duration: 6000, panelClass: ['error'] });
23415
23422
  }
23416
- /* Internal server error */
23423
+ /* Handle internal server errors for status code 500 */
23417
23424
  if (error.status == 500) {
23418
23425
  this.snackBar.open(error.text(), undefined, { duration: 6000, panelClass: ['error'] });
23419
23426
  }
23420
23427
  }));
23421
23428
  }
23422
23429
  /**
23423
- * Parses http response errors
23424
- * @param error
23430
+ * Parses HTTP response errors and extracts the error messages.
23431
+ * Handles both ArrayBuffer and structured error objects.
23432
+ *
23433
+ * @param error The error object to parse, which could be an ArrayBuffer or a structured error object.
23434
+ * @returns A string containing all error messages, joined by new lines.
23425
23435
  */
23426
23436
  parseErrors(error) {
23427
23437
  let errors = [];
23438
+ /* Check if error exists before processing */
23428
23439
  if (error) {
23429
- Object.keys(error).forEach(el => {
23430
- let err = error[el];
23431
- if (Array.isArray(err)) {
23432
- err.forEach(err => {
23433
- errors.push(err);
23434
- });
23440
+ /* If the error is an ArrayBuffer, attempt to decode and parse it */
23441
+ if (error instanceof ArrayBuffer) {
23442
+ try {
23443
+ /* Decode the ArrayBuffer to a string and then parse the JSON */
23444
+ error = JSON.parse(new TextDecoder().decode(new Uint8Array(error)));
23435
23445
  }
23436
- else if (typeof err === "string") {
23437
- errors.push(err);
23446
+ catch (err) {
23447
+ /* Log the error if JSON parsing fails */
23448
+ console.error("Error parsing ArrayBuffer:", err);
23449
+ /* Return a generic message if parsing fails */
23450
+ return "Failed to parse error details.";
23438
23451
  }
23439
- });
23452
+ }
23453
+ /* Ensure the error is an object (for structured error responses) */
23454
+ if (typeof error === 'object') {
23455
+ /* Iterate over the keys of the error object */
23456
+ Object.keys(error).forEach(el => {
23457
+ let err = error[el];
23458
+ /* If the value is an array, iterate over each element */
23459
+ if (Array.isArray(err)) {
23460
+ err.forEach(e => {
23461
+ /* Ensure each element is a string before adding to errors */
23462
+ if (typeof e === 'string') {
23463
+ errors.push(e);
23464
+ }
23465
+ });
23466
+ }
23467
+ else if (typeof err === 'string') {
23468
+ /* If the value is a string, add it directly to the errors list */
23469
+ errors.push(err);
23470
+ }
23471
+ });
23472
+ }
23440
23473
  }
23474
+ /* Join the error messages with newlines and return the result */
23441
23475
  return errors.join('\n');
23442
23476
  }
23443
23477
  /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: BaseInterceptor, deps: [{ token: AppSetting }, { token: i2$4.MatSnackBar }], target: i0.ɵɵFactoryTarget.Injectable });