There is simple method returning Ok:
[HttpGet("request_name")]
public IActionResult request_name()
{
using (var db = new WordContext())
{
return Ok("This is ok response string");
}
}
And simple request in ngx:
request_name() {
return this.http
.get<string>(`${this.apiUrl}/request_name`);
}.subscribe(x => {
});
I can see code 200 "This is ok response string" in chrome, but there is error message in chrome console:
ERROR HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:4200/main/name/request_name", ok: false, …}
What does it mean and how do I solve it?
Updated
The error message:
error:
error: SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:5010/vendor.js:7457:51) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:5010/polyfills.js:2743:31) at Object.onInvokeTask (http://localhost:5010/vendor.js:36915:33) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:5010/polyfills.js:2742:36) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:5010/polyfills.js:2510:47) at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:5010/polyfills.js:2818:34) at invokeTask (http://localhost:5010/polyfills.js:3862:14) at XMLHttpRequest.globalZoneAwareCallback (http://localhost:5010/polyfills.js:3888:17)
message: "Unexpected token T in JSON at position 0"
stack: "SyntaxError: Unexpected token T in JSON at position 0↵ at JSON.parse (<anonymous>)↵ at XMLHttpRequest.onLoad (http://localhost:5010/vendor.js:7457:51)↵ at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:5010/polyfills.js:2743:31)↵ at Object.onInvokeTask (http://localhost:5010/vendor.js:36915:33)↵ at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:5010/polyfills.js:2742:36)↵ at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:5010/polyfills.js:2510:47)↵ at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:5010/polyfills.js:2818:34)↵ at invokeTask (http://localhost:5010/polyfills.js:3862:14)↵ at XMLHttpRequest.globalZoneAwareCallback (http://localhost:5010/polyfills.js:3888:17)"
__proto__: Error
text: "This is ok response string"
__proto__: Object
headers: HttpHeaders
lazyInit: ƒ ()
lazyUpdate: null
normalizedNames: Map(0) {}
__proto__: Object
message: "Http failure during parsing for http://localhost:5005/main/word/request_name"
name: "HttpErrorResponse"
ok: false
status: 200
statusText: "OK"
url: "http://localhost:5005/main/word/request_name"
ERROR: HttpErrorResponse ..., which are the details of an error object. Could you update your question with the complete object details? - Jota.ToledoHttpClienttries to parse an invalid JSON string. See angular.io/guide/http#requesting-non-json-data - Jota.Toledo