18

I am trying to send a HTTP GET request from my Angular2/ionic2 app using http.get. The HTTP GET request contains a valid Linkedin access token and is supposed to return some profiledata. However, the following error occurs when getProfileData() is called:

3     229881   group    EXCEPTION: Response with status: 0  for URL: null
4     229895   error    EXCEPTION: Response with status: 0  for URL: null
5     229909   groupEnd
6     229950   error    Uncaught Response with status: 0  for URL: null, http://192.168.178.49:8100/build/js/app.bundle.js, Line: 95774

Still:

  • The GET request with the same URL works when tested on www.hurl.it
  • The GET request called from the app works with a different URL, e.g. let URL = "https://httpbin.org/get?name=hannes"

onboarding-load.ts:

import { Component } from '@angular/core';
import { NavController, Platform, Alert } from 'ionic-angular';
import { OnboardingHelloPage } from '../onboarding-hello/onboarding-hello';
import { CordovaOauth, LinkedIn } from 'ng2-cordova-oauth/core';    
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map'


@Component({
  templateUrl: 'build/pages/onboarding-load/onboarding-load.html',
})
export class OnboardingLoadPage {
  private data;
  private code;

constructor(private navCtrl: NavController, private platform: Platform, private http: Http) {
    this.http = http;
    this.navCtrl = navCtrl;
  }

public getProfileData() {
  let URL = "https://api.linkedin.com/v1/people/~?oauth2_access_token=SOMEVALIDTOKEN&format=json";
  //let URL = "https://httpbin.org/get?name=hannes"

  this.http.get(URL)
    .map(res => res.json())
    .subscribe(data => {
      this.data = data;
      console.log(JSON.stringify(data));
  });
  // go to next page
  this.viewOnboardingHello();
}
...
}
Hannes Kannes
  • 181
  • 1
  • 1
  • 4

5 Answers5

13

It's probably a CORS issue.
Your Angular2 APP is hosted on another server than the API you're calling.

If you want to bypass this (only for test purposes), install this Chrome extension and add

Access-Control-Allow-Origin:

to your headers.
For real usage you should call the API from your server(Node, PHP, Python ...) (where the angular2 APP is hosted) and pass data to your angular2 APP.

zx485
  • 28,498
  • 28
  • 50
  • 59
Jan Giacomelli
  • 1,299
  • 11
  • 23
4

As a side note, this also happens when the server is just offline.

I ended up here because I was wondering if there was an official meaning to status 0 and URL null.

Arnaud P
  • 12,022
  • 7
  • 56
  • 67
  • Is there any solution in case the server is offline? – Roberto Jul 20 '17 at 16:28
  • 1
    In my case, no. To be more specific I get this kind of response when my 'data' server (a RESTful API) is not reachable. So there is no way the Angular app can fetch any data. – Arnaud P Jul 20 '17 at 16:59
  • Update: depending on what data you need to serve, you may if fact be interested in a [Service Worker](https://angular.io/guide/service-worker-intro). That could allow your app to go over a temporary server downtime. – Arnaud P Apr 30 '18 at 07:03
4

We had some of those in our log. After a little digging it seems like they come whenever a ajax request is aborted after the browser started navigating to a new url.

Esben Skov Pedersen
  • 4,437
  • 2
  • 32
  • 46
0

I having similar issue when running Jesmine/Karma unit test. After checking long time,I came to know that this issue is because of some services are not mocked properly. When test case loaded service calls were aborted by the browser. Hence this error is coming.

Ben P
  • 197
  • 2
  • 15
0

There are a few reasons for this.

a) the network is out. disconnect from wifi and you will see this.

b) The middle ware is cancelling the call. I have a middle ware that is terminating back end connections dead in 30 seconds, not a http time out. I think this is a middleware problem, it should be a http time out.

c) Changing URL on search bar. Angular takes control of the URL bar somehow so that it changes without reloading. I notice that this sometimes does not happen and the existing network calls are cancelled. I had to lock the screen for some activities. I also notice this does not happen after angular is completely started.

Some solutions.

  • I know there is a query on network status, have not coded this yet.
  • Timeout due to long running, obviously tune your service calls.
  • locking the screen until services are completed
oo Waratah
  • 31
  • 4