From 92f8ee6a11b7350baaa60546d96c284d003a204e Mon Sep 17 00:00:00 2001 From: Cathy Hu Date: Fri, 11 Sep 2020 18:40:35 +0200 Subject: [PATCH] [email] Add immediate response if email is in list --- .../src/app/core/auth/error.interceptor.ts | 5 +---- .../email-bot-card/email-bot-card.component.ts | 16 +++++++++------- kibicara/platforms/email/webapi.py | 3 +++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/kibicara-frontend/src/app/core/auth/error.interceptor.ts b/kibicara-frontend/src/app/core/auth/error.interceptor.ts index 4fa8e08..eaf1315 100644 --- a/kibicara-frontend/src/app/core/auth/error.interceptor.ts +++ b/kibicara-frontend/src/app/core/auth/error.interceptor.ts @@ -28,8 +28,6 @@ export class ErrorInterceptor implements HttpInterceptor { return next.handle(request).pipe( catchError((err: HttpErrorResponse) => { if (err.error instanceof ProgressEvent) { - // TODO Add spinner/overlay in app to prevent user input - console.log('Networkerror'); this.snackBar.openFromComponent(OverlayComponent, { verticalPosition: 'top', }); @@ -42,8 +40,7 @@ export class ErrorInterceptor implements HttpInterceptor { } else if (err.status === 404) { this.router.navigate(['/404']); } - const error = err.error.message || err.statusText; - return throwError(error); + return throwError(err); }) ); } diff --git a/kibicara-frontend/src/app/platforms/email/email-bot-card/email-bot-card.component.ts b/kibicara-frontend/src/app/platforms/email/email-bot-card/email-bot-card.component.ts index 3801c55..01474c7 100644 --- a/kibicara-frontend/src/app/platforms/email/email-bot-card/email-bot-card.component.ts +++ b/kibicara-frontend/src/app/platforms/email/email-bot-card/email-bot-card.component.ts @@ -58,13 +58,15 @@ export class EmailBotCardComponent implements OnInit { ); }, (error) => { - this.snackBar.open( - 'Could not send e-mail to this address. Try again!', - 'Close', - { - duration: 2000, - } - ); + let errorMsg = 'Unknown error'; + if (error.status === 409) { + errorMsg = 'E-Mail already in list.'; + } else if (error.status === 502) { + errorMsg = 'Could not send e-mail to this address. Try again!'; + } + this.snackBar.open(errorMsg, 'Close', { + duration: 2000, + }); } ); } diff --git a/kibicara/platforms/email/webapi.py b/kibicara/platforms/email/webapi.py index 3c45f9e..311f975 100644 --- a/kibicara/platforms/email/webapi.py +++ b/kibicara/platforms/email/webapi.py @@ -196,6 +196,9 @@ async def email_subscribe( token, ) try: + subs = await EmailSubscribers.objects.filter(email=subscriber.email).all() + if subs: + raise HTTPException(status_code=status.HTTP_409_CONFLICT) email.send_email( subscriber.email, "Subscribe to Kibicara " + hood.name,