Http failure response for (unknown url): 0 Unknown Error

28,662 views
Skip to first unread message

olabanji tajudeen

unread,
Nov 20, 2017, 7:47:03 AM11/20/17
to Angular and AngularJS discussion
Hi everyone I am new to angular. My first project trying to get data from an API throws this error "Http failure response for (unknown url): 0 Unknown Error". Please I want to know what could have been causing this error. Thanks in advance for your response.

Sander Elias

unread,
Nov 20, 2017, 7:54:31 AM11/20/17
to Angular and AngularJS discussion
Hi Olebanji,

Error 0 is what you get when de request does not go out. Most common cause of this is that CORS is not configured correctly on the server. Let me rephrase that to: In 98% of the cases, this is a server side issue. Even in the case postman works.

look up CORS

Regards
Sander

olabanji tajudeen

unread,
Nov 22, 2017, 2:47:34 AM11/22/17
to Angular and AngularJS discussion
Thanks Sander for the response. I am using asp.net web api as the back end server I configured my CORS I still get the same error

Sander Elias

unread,
Nov 22, 2017, 9:41:15 AM11/22/17
to Angular and AngularJS discussion
Hi Olebanji,

Open up the network tab and look at the details in there. Also, make sure you look at what kind of request it is that fails. I suspect your server is erroring out on the "options" request.

Regards
Sander

olabanji tajudeen

unread,
Nov 23, 2017, 12:08:36 PM11/23/17
to Angular and AngularJS discussion
Thanks sander I did not configure CORS very well on the server. Now I have fixed it and its returning response but the response is not showing on the page I had to inspect the code and found out it returned object in 4 places. I think I will have to serialize it to the object I have on the client. I dont know how to go about that. I have "Category" class on the server I created "Category" with the same fields in my angular like this 

export class Category {
  id: number;
  name: string;
}

I called the server like this 

getCategories (): Observable<Category[]> {
  return this.http.get<Category[]>('http://localhost:56757/api/product/categories')
    .pipe(
      tap(categories` => this.log(`fetched categories`)),
      catchError(this.handleError('getCategories', []))
    );
}


HTML :

 <ul>
  <li *ngFor="let cat of categories">
    <span class="badge">{{cat.id}}</span> {{cat.name}}
  </li>
</ul>

On Monday, November 20, 2017 at 1:47:03 PM UTC+1, olabanji tajudeen wrote:

Sander Elias

unread,
Nov 23, 2017, 9:51:40 PM11/23/17
to Angular and AngularJS discussion
Hi Olebanji,

Your code doesn't show me if you are injecting http, or httpclient. HttpClient does the json unrwapping.
Given what I know of java backends, you might need to unwrap it a bit more. I think what you get is something like:

interface javaResponse {

   
Category: {
      id
: number;
      name
: string;

   
}[]
}

that's not the actual code, but it should get you going.

Regards
Sander

olabanji tajudeen

unread,
Nov 27, 2017, 3:58:11 AM11/27/17
to Angular and AngularJS discussion
Thanks Sander I think I need to update to version 5.0

olabanji tajudeen

unread,
Dec 5, 2017, 1:52:11 PM12/5/17
to Angular and AngularJS discussion
Hi Sander I'm still on this issue now i'm using angular 5.0 still not seeing the data returned, But I know data is returning because I use *ngfor on <li> tag it repeating the number of data in my database Pls I need help on this I have been on it for the past 3 weeks


On Friday, November 24, 2017 at 3:51:40 AM UTC+1, Sander Elias wrote:
Reply all
Reply to author
Forward
0 new messages