Skip to content

Commit 2eb9dc2

Browse files
committed
(fix) Proper error handling in HTTP requests
1 parent 9a80ef0 commit 2eb9dc2

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

src/home/home.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ export class Home {
4747
this.http.get(url)
4848
.subscribe(
4949
response => this.response = response.text(),
50-
error => this.response = error.json().message
50+
error => this.response = error.text()
5151
);
5252
}
5353
if (type === 'Secured') {
5454
// For protected routes, use AuthHttp
5555
this.authHttp.get(url)
5656
.subscribe(
5757
response => this.response = response.text(),
58-
error => this.response = error.json().message
58+
error => this.response = error.text()
5959
);
6060
}
6161
}

src/login/login.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export class Login {
2929
this.router.parent.navigateByUrl('/home');
3030
},
3131
error => {
32-
alert(error.json().message);
33-
console.log(error.json().message);
32+
alert(error.text());
33+
console.log(error.text());
3434
}
3535
);
3636
}

src/signup/signup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export class Signup {
2929
this.router.parent.navigateByUrl('/home');
3030
},
3131
error => {
32-
alert(error.json().message);
33-
console.log(error.json().message);
32+
alert(error.text());
33+
console.log(error.text());
3434
}
3535
);
3636
}

typings/_custom/webpack.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare var require: any;
2+
declare var __filename: string;
3+
declare var __dirname: string;
4+
declare var global: any;

typings/tsd.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
/// <reference path="_custom/custom.d.ts" />
2-
/// <reference path="whatwg-fetch/whatwg-fetch.d.ts" />

0 commit comments

Comments
 (0)