Jared Ostyn February 2016

Aurelia: fetch-client response doesn't have my data

I've been banging my head against fetch-client for too long and I need some help.

I'm getting some data from Skyscanner. The request hits their API and Chrome's dev tools list it in the network tab as a complete fetch request with code 200 and the correct response body.

import {inject} from 'aurelia-framework';
import {HttpClient} from 'aurelia-fetch-client';
@inject(HttpClient)
export class Flights {
    constructor(http){
        http.configure(config => {
          config
            .withBaseUrl('http://partners.api.skyscanner.net/apiservices/')
            .withDefaults({
                mode: 'no-cors',
                headers: {
                    'Accept': 'application/json',
                    'Content-type' : 'application/json'
                }
            });
        });

        this.data = "";
        this.http = http;
    }
  activate() {
    this.http.fetch('browsequotes/v1.0/GB/GBP/en-GB/UK/anywhere/anytime/anytime?apiKey=MYAPIKEYGOESHERE')
            .then(response => {
                console.log(response);
                console.log(response.response);
                console.log(response.content);
                console.log(response.data);
            })
            .catch(ex => {
                console.log(ex);
            }); 
  }
}

But when the response object is printed it has NOTHING in it:

Response {}
  body: null
  bodyUsed: false
  headers: Headers
  __proto__: Headers
  ok: false
  status: 0
  statusText: ""
  type: "opaque"
  url: ""
  __proto__: Response

All of the remaining console.log's produce undefined

Am I using fetch-client incorrectly? What am I missing?

Answers


Salva February 2016

Notice you're receiving an opaque response (type: "opaque"). Opaque responses does not allow you to read them. This is due to the no-cors mode you set before. You should use the cors mode and SkyScanner should provide the proper headers for your API key which is something I think they don't do.

Post Status

Asked in February 2016
Viewed 1,258 times
Voted 8
Answered 1 times

Search




Leave an answer