Im trying to figure out how to get a console message from the Http response
But i constantly get Red Error message in the console log even when the Http request seems to be succesfull
Service:
CreateItem(val: any){
return this.http.post(this.ApiUrl + '/FoodItems/Create-Item', val,{ observe: 'response'});
}
component
CreateItem(){
this.sharedService.CreateItem(this.val).subscribe(
(val) => console.log("getting log value", val)
}
when i start CreateItem() it did add an object to the database so it seems like it is succesfull but i always get a red error message in the console.log :
core.mjs:6495 ERROR
1. HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: ‘OK’, url: ‘https://localhost:44355/api/FoodItems/Create-Item’, ok: false, …}
-
- error: {error: SyntaxError: Unexpected token S in JSON at position 0 at JSON.parse () at XMLHtt…, text: ‘Succesfull uploaded’}*
-
- headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}*
-
- message: “Http failure during parsing for https://localhost:44355/api/FoodItems/Create-Item”*
-
- name: “HttpErrorResponse”*
-
- ok: false*
-
- status: 200*
-
- statusText: “OK”*
-
- [[Prototype]]: HttpResponseBase*