0

After re-installing node_modules and using json() to my fetch call, I still receive an blob response. Here is my code:

export function test() {
  const url = 'http://url/api/testServlet';
  return fetch(url, {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json' 
    }
  })
  .then((data) => {
        console.log("data ", data, " --- end data");
        data.json();
  })
  .catch((error) => {
    console.error(error);
  });
}

With console.log, I get:

data 
{
  "_bodyBlob": {
    blob
  }, 
  "_bodyInit": {
    blob
  }, 
  "headers": {
    headers
  }, 
  "ok": true, 
  "status": 200, 
  "statusText": undefined, 
  "type": "default", 
  "url": "http://url/api/testServlet"
}  
--- fin data

EDIT : I have also an error value.hasOwnProperty('tag') that comes from nowhere I have absolutely no idea from where that comes from... I have just a component that display the result of my API call and the code I showed above.

The message is:

"Error: value.hasOwnProperty is not a function. (In 'value.hasOwnProperty('tag'), 'value.hasOwnProperty' is undefined)

I read some subjects and all was talking about this error but there was the function hasOwnProperty written in there code. Not me...

0

1 Answer 1

3

My bad. Or not. I don't know you tell me. I replaced by :

export function test() {
  return fetch('http://url/api/testServlet')
    .then((response) => response.json())
    .then((responseJson) => {
      console.log("data : ", responseJson)
      return responseJson;
    })
    .catch((error) => {
      console.error(error);
    });
}

And it worked. It may come from the const url I don't know but I'm happy. Thank you. Or thank me I don't know you tell me.

Sign up to request clarification or add additional context in comments.

1 Comment

I'll tell you: Thank you! :) This post helped me, I removed my faulty usage of chaining then+logging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.