# fetch error

**URL:** <https://forums.fusetools.com/t/fetch-error/6524>\
**Category:** Bug Reports\
**Created:** [September 30, 2016, 12:18am UTC](https://forums.fusetools.com/t/fetch-error/6524 "2016-09-30T00:18:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![1212khd](https://avatars.discourse-cdn.com/v4/letter/1/8baadc/32.png) [@1212khd](https://forums.fusetools.com/u/1212khd)\
**Post date:** [September 30, 2016, 12:18am UTC](https://forums.fusetools.com/t/fetch-error/6524/1 "2016-09-30T00:18:14Z")

</div>

Hi.  
When I use fetch, It would have some error.

This is part of my code.

```
    function getData() {
            fetch(url, {
    		method: 'POST'
    	}).then(function(response) {
    		items.value = Backend.parsingXMLData(response._bodyInit);
    		resultText.value = response.statusText+". We got the data.";
    		if (items.value.totalCount != 0) {
    			Storage.write("search.xml", response._bodyInit)
    				.then(function(succeeded) {
            			        if(succeeded) {
    						console.log("Successfully wrote to file.");
        				} else {
	        				console.log("Couldn't write to file.");
		        		}
		        	});
        	}
    	}).catch(function(error) {
    		console.log(JSON.stringify(error));
    	});
    }

    function getSido() {
	if (address.data1.length == 0) {
		fetch(url, {
			method: 'POST'
		}).then(function(response) {
			code.value = Backend.parsingXMLData(response._bodyInit);
			code.value.items.forEach(function(item) {
				address.data1.add(item.item.ADDR1);
			})
			if (code.value.totalCount > 10) {
				url = url + '&pageNo=';
				for (var i = 2 ; (i-1)*10 <= code.value.totalCount ; i++) {
					fetch(url+i, {
						method: 'POST'
					}).then(function(response) {
						code.value = Backend.parsingXMLData(response._bodyInit);
						code.value.items.forEach(function(item) {
							address.data1.add(item.item.ADDR1);
						})
					});
				}
			}
		}).catch(function(error) {
			console.log(JSON.stringify(error));
		});
	}
    }

function getSgk() {
	if (address.data1.length == 0) {
		fetch(url, {
			method: 'POST'
		}).then(function(response) {
			code.value = Backend.parsingXMLData(response._bodyInit);
			code.value.items.forEach(function(item) {
				address.data2.add(item.item.ADDR2);
			})
			if (code.value.totalCount > 10) {
				url = url + '&pageNo=';
				for (var i = 2 ; (i-1)*10 <= code.value.totalCount ; i++) {
					fetch(url+i, {
						method: 'POST'
					}).then(function(response) {
						code.value = Backend.parsingXMLData(response._bodyInit);
						code.value.items.forEach(function(item) {
							address.data2.add(item.item.ADDR2);
						})
					});
				}
			}
		}).catch(function(error) {
			console.log(JSON.stringify(error));
		});
	}
    }

```

This code is well in Local Preview.

But, isn’t well in iOS Preview.

getSido is running well. But, getData and getSgk is not running.  
And it send Same error message. “line:435, column:29, sourceUrl:js/fetch.js”

Fuse version: 0.26.0  
OS X 10.11.6

---

<div class="post-metadata">

**Author:** ![BeeWarloc](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/beewarloc/32/186_2.png) [@BeeWarloc](https://forums.fusetools.com/u/BeeWarloc)\
**Post date:** [September 30, 2016, 8:25am UTC](https://forums.fusetools.com/t/fetch-error/6524/2 "2016-09-30T08:25:09Z")

</div>

Hi, thanks for the bug report. 🙂

In general it can be hard for us to reproduce your problem with only a part of your code. If it is possible for you to provide a self-contained example demonstrating the problem that would be very helpful!

---

<div class="post-metadata">

**Author:** ![1212khd](https://avatars.discourse-cdn.com/v4/letter/1/8baadc/32.png) [@1212khd](https://forums.fusetools.com/u/1212khd)\
**Post date:** [October 1, 2016, 12:26am UTC](https://forums.fusetools.com/t/fetch-error/6524/3 "2016-10-01T00:26:58Z")

</div>

Thanks for your reply.

[https://github.com/HandongKim/BugReport](https://github.com/HandongKim/BugReport)

This is the example.

It has functions getSido, getSgk, getEmd.

getSido run fine. But, getSgk send same error message.

---

<div class="post-metadata">

**Author:** ![BeeWarloc](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/beewarloc/32/186_2.png) [@BeeWarloc](https://forums.fusetools.com/u/BeeWarloc)\
**Post date:** [October 18, 2016, 4:32pm UTC](https://forums.fusetools.com/t/fetch-error/6524/4 "2016-10-18T16:32:59Z")

</div>

Hi, thanks for the example.

I have been away on vacation for a while and forgot about this thread, so sorry for the late reply.

I cloned your BugReport repo and attempted to run it, but I’m not sure what I should be looking for here.  
The first thing I noticed was that I got a JS error in [fetchBug.ux:206](https://github.com/HandongKim/BugReport/blob/master/fetchBug.ux#L206), but that seem to be because the properties names are missing.

When I change these lines to:

```auto
		module.exports = {
			address: address,
			getData1: getData1,
			getData2: getData2,
			getData3: getData3,
			selectData1: selectData1,
			selectData2: selectData2,
			selectData3: selectData3
		};

```

I get rid of _that_ error message.

After that when i push the `fetchData` buttons I seem to get some Korean text back, but unfortunately I don’t know if that is what is expected. Sadly I don’t know any Korean. 😉

I also see you recently made a couple additional commits to the BugReport repo. Are these intended, or should I rather try the initial commit?

---

<div class="post-metadata">

**Author:** ![1212khd](https://avatars.discourse-cdn.com/v4/letter/1/8baadc/32.png) [@1212khd](https://forums.fusetools.com/u/1212khd)\
**Post date:** [October 19, 2016, 12:26pm UTC](https://forums.fusetools.com/t/fetch-error/6524/5 "2016-10-19T12:26:31Z")

</div>

Thanks for your reply.

That is not what I intended.  
I have translated commit to English.  
Plz check again. 🙂

---

<div class="post-metadata">

**Author:** ![BeeWarloc](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/beewarloc/32/186_2.png) [@BeeWarloc](https://forums.fusetools.com/u/BeeWarloc)\
**Post date:** [October 24, 2016, 9:13am UTC](https://forums.fusetools.com/t/fetch-error/6524/6 "2016-10-24T09:13:29Z")

</div>

Ok, I will have another look at it now.

I see here that it’s really 4 separate issues you got. I will take a quick look at all of them, but for future discussion it will be best if you open a separate forum post for the ones unrelated to this post.

That makes it a lot easier for us to track the issues and follow the discussion.

And thanks again, we really appreciate you putting an effort into creating an example which demonstrates these problems, it’s very helpful 🙂

---

<div class="post-metadata">

**Author:** ![BeeWarloc](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/beewarloc/32/186_2.png) [@BeeWarloc](https://forums.fusetools.com/u/BeeWarloc)\
**Post date:** [October 24, 2016, 10:08am UTC](https://forums.fusetools.com/t/fetch-error/6524/7 "2016-10-24T10:08:21Z")

</div>

Regarding the fetch bug:

From what I can tell “fetchData” fetches the url. The second time I press it nothing happens, which would be expected as `address.data1` has now been modified (so [fetchBug.ux:126](https://github.com/HandongKim/BugReport/blob/master/fetchBug.ux#L126) is no longer true).

However, the “fetchData2” and “fetchData3” buttons don’t seem to do anything because `data.sido` is set to “시도” and `data.sgk` is set to “시군구”, due to the surrounding if blocks.

But from what I can tell this is all expected behavior for this code. Or is it something I’m missing here?

EDIT:

Ok, after going through the code a bit closer, I now understand I need to click on the downloaded data1 text. Then I get an error in fetch.js:435. Will look a bit more at exactly why.

---

<div class="post-metadata">

**Author:** ![1212khd](https://avatars.discourse-cdn.com/v4/letter/1/8baadc/32.png) [@1212khd](https://forums.fusetools.com/u/1212khd)\
**Post date:** [October 24, 2016, 10:46am UTC](https://forums.fusetools.com/t/fetch-error/6524/8 "2016-10-24T10:46:48Z")

</div>

Thank you for your quick reply.

Among the issues that I posted, Scrollview issue seems to be solved in new release. I will check that issue.

Then I will post a new forum related to the other issues.

It would be very helpful if you check the fetch issue. 🙂

---

<div class="post-metadata">

**Author:** ![BeeWarloc](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/beewarloc/32/186_2.png) [@BeeWarloc](https://forums.fusetools.com/u/BeeWarloc)\
**Post date:** [October 24, 2016, 10:57am UTC](https://forums.fusetools.com/t/fetch-error/6524/9 "2016-10-24T10:57:25Z")

</div>

I just found out what the problem is. It looks like the HTTP backend used on iOS does not support UTF-8 characters in the URI. IIRC compliant URI’s should not contain unencoded UTF-8 characters, so `encodeURIComponent` must be used, which is a good thing to do in any case when building an URI.

Specifically if you replace the line [fetchBug.ux:144](https://github.com/HandongKim/BugReport/blob/master/fetchBug.ux#L144) with:

```auto
var url = 'http://openapi.onbid.co.kr/openapi/services/OnbidCodeInfoInquireSvc/getOnbidAddr2Info?ServiceKey=LEVQhgclvGUKoC%2BJrvokKajzK6OsTFRinprds4qBzZj1PJMDZUQ8SRTm0lmzbj1jzC9IaZLqEm1G%2FhAdHV5R5A%3D%3D&numOfRows=999&ADDR1='+encodeURIComponent(address.sido.value);

```

it should work ok.

And then the other issues will be followed up in new threads, thanks for that. 🙂

---

<div class="post-metadata">

**Author:** ![1212khd](https://avatars.discourse-cdn.com/v4/letter/1/8baadc/32.png) [@1212khd](https://forums.fusetools.com/u/1212khd)\
**Post date:** [October 24, 2016, 1:44pm UTC](https://forums.fusetools.com/t/fetch-error/6524/10 "2016-10-24T13:44:05Z")

</div>

Thanks for your help.

It did help me a lot. 🙂
