Added error message for connection refused errors sending emails

This commit is contained in:
FinnStutzenstein 2019-07-23 12:03:54 +02:00
parent 54c5410bb8
commit a60719bcc4
3 changed files with 14 additions and 9 deletions

View File

@ -29,7 +29,7 @@ export abstract class BaseViewComponent extends BaseComponent implements OnDestr
* @param translate the translate service, passed to the base component * @param translate the translate service, passed to the base component
* @param matSnackBar the snack bar service. Needed for showing errors. * @param matSnackBar the snack bar service. Needed for showing errors.
*/ */
public constructor(titleService: Title, translate: TranslateService, private matSnackBar: MatSnackBar) { public constructor(titleService: Title, translate: TranslateService, protected matSnackBar: MatSnackBar) {
super(titleService, translate); super(titleService, translate);
this.subscriptions = []; this.subscriptions = [];
} }

View File

@ -7,9 +7,9 @@ import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { environment } from 'environments/environment'; import { environment } from 'environments/environment';
import { BaseComponent } from '../../../../base.component';
import { HttpService } from 'app/core/core-services/http.service'; import { HttpService } from 'app/core/core-services/http.service';
import { ThemeService } from 'app/core/ui-services/theme.service'; import { ThemeService } from 'app/core/ui-services/theme.service';
import { BaseViewComponent } from 'app/site/base/base-view';
/** /**
* Reset password component. * Reset password component.
@ -20,7 +20,7 @@ import { ThemeService } from 'app/core/ui-services/theme.service';
templateUrl: './reset-password.component.html', templateUrl: './reset-password.component.html',
styleUrls: ['../../assets/reset-password-pages.scss'] styleUrls: ['../../assets/reset-password-pages.scss']
}) })
export class ResetPasswordComponent extends BaseComponent implements OnInit { export class ResetPasswordComponent extends BaseViewComponent implements OnInit {
/** /**
* THis form holds one control for the email. * THis form holds one control for the email.
*/ */
@ -30,15 +30,15 @@ export class ResetPasswordComponent extends BaseComponent implements OnInit {
* Constructur for the reset password view. Initializes the form for the email. * Constructur for the reset password view. Initializes the form for the email.
*/ */
public constructor( public constructor(
protected titleService: Title, titleService: Title,
protected translate: TranslateService, translate: TranslateService,
matSnackBar: MatSnackBar,
private http: HttpService, private http: HttpService,
formBuilder: FormBuilder, formBuilder: FormBuilder,
private matSnackBar: MatSnackBar,
private router: Router, private router: Router,
private themeService: ThemeService private themeService: ThemeService
) { ) {
super(titleService, translate); super(titleService, translate, matSnackBar);
this.resetPasswordForm = formBuilder.group({ this.resetPasswordForm = formBuilder.group({
email: ['', [Validators.required, Validators.email]] email: ['', [Validators.required, Validators.email]]
}); });
@ -64,7 +64,6 @@ export class ResetPasswordComponent extends BaseComponent implements OnInit {
await this.http.post<void>(environment.urlPrefix + '/users/reset-password/', { await this.http.post<void>(environment.urlPrefix + '/users/reset-password/', {
email: this.resetPasswordForm.get('email').value email: this.resetPasswordForm.get('email').value
}); });
// TODO: Does we get a response for displaying?
this.matSnackBar.open( this.matSnackBar.open(
this.translate.instant('An email with a password reset link was send!'), this.translate.instant('An email with a password reset link was send!'),
this.translate.instant('OK'), this.translate.instant('OK'),
@ -74,7 +73,7 @@ export class ResetPasswordComponent extends BaseComponent implements OnInit {
); );
this.router.navigate(['/login']); this.router.navigate(['/login']);
} catch (e) { } catch (e) {
console.log('error', e); this.raiseError(e);
} }
} }
} }

View File

@ -838,6 +838,12 @@ class PasswordResetView(APIView):
"detail": f"Error {e.smtp_code}: Authentication failure. Please contact your administrator." "detail": f"Error {e.smtp_code}: Authentication failure. Please contact your administrator."
} }
) )
except ConnectionRefusedError:
raise ValidationError(
{
"detail": "Connection refused error. Please contact your administrator."
}
)
return super().post(request, *args, **kwargs) return super().post(request, *args, **kwargs)
def get_users(self, email): def get_users(self, email):