Skip to content
Advertisement

Tag: fetch-api

fetch response.text() returns pending promise

I test the fetch API with jsonplaceholder URL, but my function returns “Promise State: Pending”, and I don’t understand why : I think the problem is because of asynchronous/synchronous methods? Answer I think the problem become asynchrone/synchrone method ? Yes. You’ve (mostly) correctly consumed the original fetch() promise, but text() also returns a promise. So: At #1 above, we respond

JS Fetching batch data with HTTP

My RESTful service allows batching requests. I’m trying to combine requests into one batch with help of Fetch API: However it returns an error – bad request. I suppose I may combine HTTP requests in wrong way. Is there simpler way of doing this? Where in Network Chrome Dev Tools can I see nested HTTP requests? Answer Your code does

Text response is empty when using fetch

The following code: is outputting: If I use curl: I get a token in text form back (length != 0). And if I output the response header via: I get: Why am I getting no text via fetch? Answer Remove mode: ‘no-cors’. When you use no-cors mode, you’re explicitly specifying that you want an “opaque response”. Your script can’t access

Getting Text From Fetch Response Object

I’m using fetch to make API calls and everything works but in this particular instance I’m running into an issue because the API simply returns a string — not an object. Typically, the API returns an object and I can parse the JSON object and get what I want but in this case, I’m having trouble finding the text I’m

Retrieve data from a ReadableStream object?

How may I get information from a ReadableStream object? I am using the Fetch API and I don’t see this to be clear from the documentation. The body is being returned as a ReadableStream and I would simply like to access a property within this stream. Under Response in the browser dev tools, I appear to have this information organised

How to handle errors in fetch() responses with Redux-Saga?

I try to handle Unauthorized error from server using redux-saga. This is my saga: I fetch data like this: But anyway result is {type: ‘LOG_IN_SUCCEEDED’, user: undefined} when I expect {type: ‘LOG_IN_FAILED’, error: ‘Unauthorized’}. Where is my mistake? How to handle errors right using Redux-Saga? Answer Don’t handle the then and error in your fetchUser method and your saga. Since

Accessing object in returned promise using fetch w/ react js

I have this function: Which returns this in the console: Promise {[[PromiseStatus]]: “pending”, [[PromiseValue]]: undefined} proto [[PromiseStatus]] : “resolved” I need to access the name/value pairs in the object but I can’t get to them. I’m assuming I need to take one extra step after I convert the response to json but can’t figure it out. If anyone could help

Advertisement