I am working with a secured api that requires me to send an Authorisation header on each request, this is working fine. However I have an issue with the handling of 401 responses.
My call to the API is made as follows:
let headers: Headers = new Headers();
headers.append('Authorization', 'Bearer ' + {myauthtoken});
let request = this.http.get(Utils.getUrl('/somesecuredmethod'), { headers: headers });
request.subscribe(
result => { this.setLoginDetails(result); },
error => {
this.loginFailed = true;
this.reasonLoginFailed = error;
return true;
});
Within error I can see the response code 401, however I also see the following in the chrome console
GET https://localhost/somesecuredmethod 401 (User not found in database.)
Does anyone know how I can get the message text in angular ?
Thanks, Jon.
EDIT:
I have previously called this same method using pure ajax as below and can get the error text.
$.ajax({
url: baseurl + "/somesecuredmethod",
method: "get",
headers: { 'Authorization': 'Bearer ' + accessToken }
}).done(function (data) {
// do something with the success
}).fail(function (jqXHR, status, err) {
$("#loading_application").addClass("hidden");
$("#login_failed_reason").text(err); <--- here I can the error text shown in the dev console
$("#login_failed").removeClass("hidden");
});