Aurelia: fetch-client response does not have my data

I banged my fetch-client head too long and I need help.

I get some data from Skyscanner. The request falls into their API, and the Chrome dev tools list it on the network tab as a complete query for the selection 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, there is NOTHING in it:

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

All other console.log produce undefined

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

+4
source share
2 answers

, (type: "opaque"). . - no-cors, . cors, SkyScanner API, , , .

+3

, , , - . , , ...

.then(response => {response.json()})
.then(data => console.log(data))

, , :

.then(response => response.json())
.then(data => console.log(data))

.then(response => { return response.json()})
.then(data => console.log(data))

Aurelia Fetch, Javascript.

0
source

Source: https://habr.com/ru/post/1627742/


All Articles