Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Data Fetching #1

Open
Ardakilic opened this issue Oct 4, 2021 · 2 comments
Open

Error on Data Fetching #1

Ardakilic opened this issue Oct 4, 2021 · 2 comments
Labels
good first issue Good for newcomers

Comments

@Ardakilic
Copy link

Ardakilic commented Oct 4, 2021

Hello,

I get error on data fetching.

Totally fresh installation on node v 16 (v16.6.2 to be exact), both error appears on Linux and macOS.

npm cache is cleared before installation.

Here's the files:

{
  "dependencies": {
    "tcmb-exchange-rates": "^0.1.10"
  }
}
var tcmb = require('tcmb-exchange-rates');
tcmb()
    .then(function(data) {
        console.log(data);
    })
    .catch(function(error) {
        console.log(error);
    });

And here's the error when I run the package:

node:events:371
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read property 'Currency' of undefined
    at /Users/arda/projects/tcmb/node_modules/tcmb-exchange-rates/lib/index.js:280:79
    at Parser.<anonymous> (/Users/arda/projects/tcmb/node_modules/xml2js/lib/parser.js:304:18)
    at Parser.emit (node:events:394:28)
    at SAXParser.onclosetag (/Users/arda/projects/tcmb/node_modules/xml2js/lib/parser.js:262:26)
    at emit (/Users/arda/projects/tcmb/node_modules/sax/lib/sax.js:624:35)
    at emitNode (/Users/arda/projects/tcmb/node_modules/sax/lib/sax.js:629:5)
    at closeTag (/Users/arda/projects/tcmb/node_modules/sax/lib/sax.js:889:7)
    at SAXParser.write (/Users/arda/projects/tcmb/node_modules/sax/lib/sax.js:1436:13)
    at Parser.exports.Parser.Parser.parseString (/Users/arda/projects/tcmb/node_modules/xml2js/lib/parser.js:323:31)
    at Parser.parseString (/Users/arda/projects/tcmb/node_modules/xml2js/lib/parser.js:5:59)
Emitted 'error' event on Parser instance at:
    at Parser.exports.Parser.Parser.parseString (/Users/arda/projects/tcmb/node_modules/xml2js/lib/parser.js:327:16)
    at Parser.parseString (/Users/arda/projects/tcmb/node_modules/xml2js/lib/parser.js:5:59)
    at exports.parseString (/Users/arda/projects/tcmb/node_modules/xml2js/lib/parser.js:369:19)
    at Request._callback (/Users/arda/projects/tcmb/node_modules/tcmb-exchange-rates/lib/index.js:271:13)
    at Request.self.callback (/Users/arda/projects/tcmb/node_modules/request/request.js:185:22)
    at Request.emit (node:events:394:28)
    at Request.<anonymous> (/Users/arda/projects/tcmb/node_modules/request/request.js:1154:10)
    at Request.emit (node:events:394:28)
    at IncomingMessage.<anonymous> (/Users/arda/projects/tcmb/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:513:28)

When I digged the code I realized the rejects don't have return, which continues to execute the code, which results the error.

Also, when I try to fetch the XML code with the library, this is what today.xml is returned as:

<html><body onload='resend();'>
<script>
function resend() {
	document.cookie="sto-idd=4062e083a73e53d0; max-age=1; path=/";
	window.location.reload();
}
</script>
</body>
</html>

So, I believe the promise rejects and the user agents for fetching can be optimized.

Thanks in advance,

@Ardakilic
Copy link
Author

Since the last 2 weeks, there has been no issues. I believe it was TCMB's server's fluke. However, since the error was not handled I'm leaving this open. Feel free to close it.

@alisabrigok alisabrigok added the good first issue Good for newcomers label Nov 3, 2021
@alisabrigok
Copy link
Owner

Sorry for the late response and thanks for reporting the issue.

It seems quite the case that rejections are not returned and the nested property access for objects is not very well handled.

I already want to clean up this package by rewriting with ESNext and ship polyfilled and also return the latest exchange rates prior to the public holidays instead of returning an error (with optionally enabled to not to have breaking changes) but unfortunately, life keeps getting in the way.

I'm happy that the package was useful to you and I'm glad that it works again after, seemingly, the missing data issue by TCMB was fixed.

For now, I'm leaving the issue open to come back to solve it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants