0

I have a login endpoint that I'm send a request to with angular's Http.get. When I send incorrect login credentials I get a JSON response back from the server with an error code 401. I can't seem to find the JSON response in the error given to the error callback. This is an ionic 3 app using angular 4. How do I get that response body I see in PostMan out of the error given to me by Angular Http?

URL

http://localhost:8080/v1.0/login?rolename=Customer&username=customer00&password=wrongpass

Postman Response Body

{
   "status": "login failed - bad credentials"
}

console.log("Error in login: " + JSON.stringify(error, undefined, 2));

 Error in login: {
    "_body": {
       "isTrusted": true
    },
   "status": 0,
   "ok": false,
   "statusText": "",
   "headers": {},
   "type": 3,
   "url": null
 }
Pengyy
  • 37,383
  • 15
  • 83
  • 73
codeetcetera
  • 3,213
  • 4
  • 37
  • 62

2 Answers2

0

In Angular 4, you should be using the new HttpClient. With this, you will get an HttpErrorResponse object in case of an error. To retrieve the body in case of a server side error, you can call (err: HttpErrorResponse) => console.log(err.error)

Further info can be found at the official HttpClient documentation under error handling.

Kim Kern
  • 54,283
  • 17
  • 197
  • 195
0

add this line

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: * 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> 

into app/index.html

main discussion here