Commit 3f1423e7 authored by dev0tion's avatar dev0tion

Improve error handling

parent 152d31ba
...@@ -107,7 +107,12 @@ export class LoginComponent implements OnInit { ...@@ -107,7 +107,12 @@ export class LoginComponent implements OnInit {
if (error.status === 0) { if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application."); alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) { } else if (error.status >= 400) {
alert(error); if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
} }
} }
) )
...@@ -128,7 +133,12 @@ export class LoginComponent implements OnInit { ...@@ -128,7 +133,12 @@ export class LoginComponent implements OnInit {
if (error.status === 0) { if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application."); alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) { } else if (error.status >= 400) {
alert(error); if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
} }
} }
) )
......
...@@ -101,7 +101,12 @@ export class CreateComponent { ...@@ -101,7 +101,12 @@ export class CreateComponent {
if (error.status === 0) { if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application."); alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) { } else if (error.status >= 400) {
alert(error); if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
} }
} }
) )
......
...@@ -115,7 +115,12 @@ export class RecoverComponent implements OnInit { ...@@ -115,7 +115,12 @@ export class RecoverComponent implements OnInit {
if (error.status === 0) { if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application."); alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) { } else if (error.status >= 400) {
alert(error); if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
} }
} }
); );
......
...@@ -60,7 +60,12 @@ export class DashboardComponent { ...@@ -60,7 +60,12 @@ export class DashboardComponent {
if (error.status === 0) { if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application."); alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) { } else if (error.status >= 400) {
alert(error); if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
} }
} }
) )
...@@ -82,7 +87,12 @@ export class DashboardComponent { ...@@ -82,7 +87,12 @@ export class DashboardComponent {
if (error.status === 0) { if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application."); alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) { } else if (error.status >= 400) {
alert(error); if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
} }
} }
) )
......
...@@ -44,7 +44,12 @@ export class HistoryComponent { ...@@ -44,7 +44,12 @@ export class HistoryComponent {
if (error.status === 0) { if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application."); alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) { } else if (error.status >= 400) {
alert(error); if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
} }
} }
) )
......
...@@ -33,9 +33,15 @@ export class ReceiveComponent { ...@@ -33,9 +33,15 @@ export class ReceiveComponent {
} }
}, },
error => { error => {
if (error.status >= 400) { if (error.status === 0) {
this.errorMessage = <any>error; alert("Something went wrong while connecting to the API. Please restart the application.");
console.log(this.errorMessage); } else if (error.status >= 400) {
if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
} }
} }
) )
......
...@@ -132,9 +132,15 @@ export class SendComponent { ...@@ -132,9 +132,15 @@ export class SendComponent {
} }
}, },
error => { error => {
if (error.status >= 400) { if (error.status === 0) {
this.errorMessage = error; alert("Something went wrong while connecting to the API. Please restart the application.");
console.log(this.errorMessage); } else if (error.status >= 400) {
if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].message);
}
} }
} }
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment