From 7f3e9f4fd0a6f1614734f827e0915ddbbb82ffb5 Mon Sep 17 00:00:00 2001 From: piratefinn Date: Fri, 15 Sep 2017 17:33:34 +0100 Subject: [PATCH] Added better error messaging --- CHANGELOG.md | 1 + src/app/auth/register.component.html | 26 ++++++------- src/app/auth/register.component.ts | 37 ++++++++++++++----- src/app/dashboard/account-edit.component.html | 4 +- src/app/dashboard/account-edit.component.ts | 23 +++++++++++- 5 files changed, 65 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 275665b..84ec5f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Fixed register box view on login page * Made the form reset properly if adding a new one +* Added better error messages on register and account edit # v0.0.1 diff --git a/src/app/auth/register.component.html b/src/app/auth/register.component.html index dbe0c82..1a0c868 100644 --- a/src/app/auth/register.component.html +++ b/src/app/auth/register.component.html @@ -6,7 +6,7 @@

Register

Create your account

- + - +
- +
- +
- +
@@ -137,7 +137,7 @@ Form validation failed, please ensure the form is filled correctly.
diff --git a/src/app/auth/register.component.ts b/src/app/auth/register.component.ts index ebc69d2..bdb9815 100644 --- a/src/app/auth/register.component.ts +++ b/src/app/auth/register.component.ts @@ -16,7 +16,8 @@ export class RegisterComponent { organisationForm: ValidationManager; years: Object[]; registerStatus: any; - + registerStatusError: string = 'Error received, please try again.'; + constructor( private http: Http, private formBuilder: FormBuilder, @@ -51,9 +52,9 @@ export class RegisterComponent { postcode: 'required', }); } - + onSubmitCustomer() { - + console.log(this.signupForm.isValid()); if (!this.signupForm.isValid() && !this.customerForm.isValid()) { console.log("Not Valid!"); @@ -63,7 +64,7 @@ export class RegisterComponent { } let signupForm = this.signupForm.getForm().value; let customerForm = this.customerForm.getForm().value; - + let data = { token: signupForm.token, usertype: signupForm.usertype, @@ -85,14 +86,23 @@ export class RegisterComponent { this.router.navigate(['/dashboard']); }, error => { - console.log( error._body ); + console.log('Register Error'); + console.log(error); + try { + console.log(error.error); + let jsonError = error.json(); + console.log("boop"); + this.registerStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message; + } catch(e) { + this.registerStatusError = 'There was a server error, please try again later.'; + } this.registerStatus = "send_failed"; - console.log(this.registerStatus) + console.log(this.registerStatus); } ); } onSubmitOrganisation() { - + console.log(this.signupForm.isValid()); if (!this.signupForm.isValid() || !this.organisationForm.isValid()) { console.log("Not Valid!"); @@ -102,7 +112,7 @@ export class RegisterComponent { } let signupForm = this.signupForm.getForm().value; let organisationForm = this.organisationForm.getForm().value; - + let data = { token: signupForm.token, usertype: signupForm.usertype, @@ -125,7 +135,16 @@ export class RegisterComponent { this.router.navigate(['/dashboard']); }, error => { - console.log( error._body ); + console.log('Register Error'); + console.log(error); + try { + console.log(error.error); + let jsonError = error.json(); + console.log("boop"); + this.registerStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message; + } catch(e) { + this.registerStatusError = 'There was a server error, please try again later.'; + } this.registerStatus = "send_failed"; console.log(this.registerStatus); } diff --git a/src/app/dashboard/account-edit.component.html b/src/app/dashboard/account-edit.component.html index f46aca7..5d4e7b4 100644 --- a/src/app/dashboard/account-edit.component.html +++ b/src/app/dashboard/account-edit.component.html @@ -122,7 +122,7 @@ Form validation failed, please ensure the form is filled correctly. @@ -160,7 +160,7 @@ Form validation failed, please ensure the form is filled correctly. diff --git a/src/app/dashboard/account-edit.component.ts b/src/app/dashboard/account-edit.component.ts index eedd3ad..0cc6a51 100644 --- a/src/app/dashboard/account-edit.component.ts +++ b/src/app/dashboard/account-edit.component.ts @@ -14,6 +14,7 @@ export class AccountEditComponent implements OnInit { accountType: any; // @ViewChild('fileInput') fileInput; submitStatus: any; + submitStatusError: string = 'Error received, please try again.'; constructor( private http: Http, @@ -111,7 +112,16 @@ export class AccountEditComponent implements OnInit { console.log(this.submitStatus); }, error => { - console.log( error._body ); + console.log('Edit Error'); + console.log(error); + try { + console.log(error.error); + let jsonError = error.json(); + console.log("boop"); + this.submitStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message; + } catch(e) { + this.submitStatusError = 'There was a server error, please try again later.'; + } this.submitStatus = "send_failed"; console.log(this.submitStatus); } @@ -159,7 +169,16 @@ export class AccountEditComponent implements OnInit { console.log(this.submitStatus); }, error => { - console.log( error._body ); + console.log('Edit Error'); + console.log(error); + try { + console.log(error.error); + let jsonError = error.json(); + console.log("boop"); + this.submitStatusError = '"' + jsonError.error + '" Error, ' + jsonError.message; + } catch(e) { + this.submitStatusError = 'There was a server error, please try again later.'; + } this.submitStatus = "send_failed"; console.log(this.submitStatus); }