mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-22 11:45:59 +01:00
[EC-827] feat: add logging to async actions (#4206)
This commit is contained in:
parent
fcdb0ecffe
commit
5207a855be
@ -1,6 +1,7 @@
|
|||||||
import { Directive, HostListener, Input, OnDestroy, Optional } from "@angular/core";
|
import { Directive, HostListener, Input, OnDestroy, Optional } from "@angular/core";
|
||||||
import { BehaviorSubject, finalize, Subject, takeUntil, tap } from "rxjs";
|
import { BehaviorSubject, finalize, Subject, takeUntil, tap } from "rxjs";
|
||||||
|
|
||||||
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||||
import { ValidationService } from "@bitwarden/common/abstractions/validation.service";
|
import { ValidationService } from "@bitwarden/common/abstractions/validation.service";
|
||||||
|
|
||||||
import { ButtonLikeAbstraction } from "../shared/button-like.abstraction";
|
import { ButtonLikeAbstraction } from "../shared/button-like.abstraction";
|
||||||
@ -23,7 +24,8 @@ export class BitActionDirective implements OnDestroy {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private buttonComponent: ButtonLikeAbstraction,
|
private buttonComponent: ButtonLikeAbstraction,
|
||||||
@Optional() private validationService?: ValidationService
|
@Optional() private validationService?: ValidationService,
|
||||||
|
@Optional() private logService?: LogService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
get loading() {
|
get loading() {
|
||||||
@ -44,7 +46,12 @@ export class BitActionDirective implements OnDestroy {
|
|||||||
this.loading = true;
|
this.loading = true;
|
||||||
functionToObservable(this.handler)
|
functionToObservable(this.handler)
|
||||||
.pipe(
|
.pipe(
|
||||||
tap({ error: (err: unknown) => this.validationService?.showError(err) }),
|
tap({
|
||||||
|
error: (err: unknown) => {
|
||||||
|
this.logService?.error(`Async action exception: ${err}`);
|
||||||
|
this.validationService?.showError(err);
|
||||||
|
},
|
||||||
|
}),
|
||||||
finalize(() => (this.loading = false)),
|
finalize(() => (this.loading = false)),
|
||||||
takeUntil(this.destroy$)
|
takeUntil(this.destroy$)
|
||||||
)
|
)
|
||||||
|
@ -2,6 +2,7 @@ import { Directive, Input, OnDestroy, OnInit, Optional } from "@angular/core";
|
|||||||
import { FormGroupDirective } from "@angular/forms";
|
import { FormGroupDirective } from "@angular/forms";
|
||||||
import { BehaviorSubject, catchError, filter, of, Subject, switchMap, takeUntil } from "rxjs";
|
import { BehaviorSubject, catchError, filter, of, Subject, switchMap, takeUntil } from "rxjs";
|
||||||
|
|
||||||
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||||
import { ValidationService } from "@bitwarden/common/abstractions/validation.service";
|
import { ValidationService } from "@bitwarden/common/abstractions/validation.service";
|
||||||
|
|
||||||
import { FunctionReturningAwaitable, functionToObservable } from "../utils/function-to-observable";
|
import { FunctionReturningAwaitable, functionToObservable } from "../utils/function-to-observable";
|
||||||
@ -24,7 +25,8 @@ export class BitSubmitDirective implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private formGroupDirective: FormGroupDirective,
|
private formGroupDirective: FormGroupDirective,
|
||||||
@Optional() validationService?: ValidationService
|
@Optional() validationService?: ValidationService,
|
||||||
|
@Optional() logService?: LogService
|
||||||
) {
|
) {
|
||||||
formGroupDirective.ngSubmit
|
formGroupDirective.ngSubmit
|
||||||
.pipe(
|
.pipe(
|
||||||
@ -39,6 +41,7 @@ export class BitSubmitDirective implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
return awaitable.pipe(
|
return awaitable.pipe(
|
||||||
catchError((err: unknown) => {
|
catchError((err: unknown) => {
|
||||||
|
logService?.error(`Async submit exception: ${err}`);
|
||||||
validationService?.showError(err);
|
validationService?.showError(err);
|
||||||
return of(undefined);
|
return of(undefined);
|
||||||
})
|
})
|
||||||
|
@ -3,6 +3,7 @@ import { action } from "@storybook/addon-actions";
|
|||||||
import { Meta, moduleMetadata, Story } from "@storybook/angular";
|
import { Meta, moduleMetadata, Story } from "@storybook/angular";
|
||||||
import { delay, of } from "rxjs";
|
import { delay, of } from "rxjs";
|
||||||
|
|
||||||
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
||||||
import { ValidationService } from "@bitwarden/common/abstractions/validation.service";
|
import { ValidationService } from "@bitwarden/common/abstractions/validation.service";
|
||||||
|
|
||||||
import { ButtonModule } from "../button";
|
import { ButtonModule } from "../button";
|
||||||
@ -68,6 +69,12 @@ export default {
|
|||||||
showError: action("ValidationService.showError"),
|
showError: action("ValidationService.showError"),
|
||||||
} as Partial<ValidationService>,
|
} as Partial<ValidationService>,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: LogService,
|
||||||
|
useValue: {
|
||||||
|
error: action("LogService.error"),
|
||||||
|
} as Partial<LogService>,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user