Fetch Problem and Fuse.Scripting.V8.Object Error

Hello,

in the following code i send a json with a firstname, lastname and phone number and get a 200 Status Code back.

Thats good but i came never to the part ‘Do something with the result’.

Instead i came in the part ‘An error occurred somewhere in the Promise chain’ and get a Fuse.Scripting.V8.Object Error in the Monitor.

I tested the same json with an RESTeasy extension for Chrome an here i get a response back ‘{“notice”: {“text”: “Customer Added”}’.

Can help me anyone?

Thanks and sorry for my bad english

var Observable = require("FuseJS/Observable");

var username = Observable("");
var password = Observable("");
var email = Observable("");
var data = Observable();

function click() {
    var requestObject = {first_name: username.value, last_name: email.value, phone: password.value};
	var status = 0;
	var response_ok = false;

	fetch('http://slimapp.dev/api/customer/add', {
	  	method: 'POST',
	  	headers: { "Content-type": "application/json", "Accept": "application/json" },
	  	body: JSON.stringify(requestObject)
  	}).then(function(response) {
    	status = response.status;  // Get the HTTP status code
		response_ok = response.ok; // Is response.status in the 200-range?
	  	console.log("Status Code " + status);
	  	return response.json();    // This returns a promise
  	}).then(function(responseObject) {
	    // Do something with the result
	    console.log('do something');
	    data.value = responseObject;
	}).catch(function(error) {
	    // An error occurred somewhere in the Promise chain
	    console.log('error ' . error);
	    debugger;
	});
}

module.exports = {
	username: username,
	email: email,
	password: password,
	click: click,
	data: data,
};

Try to parse the response as .text() instead and look at the result. Could be that the server returns invalid JSON.

Hi,

I’m getting the same issue:

  <JavaScript>
    var Observable = require("FuseJS/Observable");
    var json = Observable();
function foo(){
 fetch('https://jsonplaceholder.typicode.com/posts/1')
.then(function(response) {
  if (!response.ok) {
    throw Error(response.statusText);
  }
  return response.json();
})
.then(function(responseAsJson) {

   json = JSON.stringify(responseAsJson);
   console.log(json);
})
.catch(function(error) {
  console.log('Looks like there was a problem:', error);
  console.log('---------------------------------------');
});
};

    module.exports = {
    foo: foo,
    }
  </JavaScript>
<Button Clicked="{foo}" Text="click"/>

and here is the log:

[Viewport]: Looks like there was a problem:
[Viewport]: Fuse.Scripting.V8.Object
[Viewport]: ---------------------------------------

Although i have tested in chrome, it works perfect:

Sorry, never mind. I got the problem, the PromiseStatus is pending.

We do not support the second argument to log that you are using. Could you try:

.catch(function(error) {
  console.log('Looks like there was a problem: ' + JSON.stringify(error));
  console.log('---------------------------------------');
});
};