Angular 6 HttpErrorResponse on POST with 200 status
By default, the Angular HttpClient tries to parse the body of the HTTP response as JSON.Since the response body that you are receiving is plain text, e.g. "Bearer .....", and not JSON, the JSON parse is failing.
You need to tell the HttpClient to expect a plain text response, like this:
this.httpClient.post(this.apiURL + '/login', user, {headers:reqHeader, responseType: 'text'});
Also note that since the response is a string, you should not be trying to cast it to a User (don't do the <User>
bit); The outgoing message is the User, the return value is a string.
i have the same error
you must change the response from json to text
datatype by default is JSON
this way make new error in observable and the solution of this case
this.httpClient.post(this.apiURL + '/login', user, {headers:reqHeader, responseType: 'text'});
in a above way i think will make new error because observable and the solution in this case
ERROR in src/app/myS.service.ts(24,54): error TS2322: Type '"text"' is not assignable to type '"json"'
you must use this pattern to solution it
returnObservable(): Observable<any> { const requestOptions: Object = { /* other options here */ headers:reqHeader responseType: 'text' } return this.http.get<any>(url, body, requestOptions);}