tobilg / facebook-events-by-location-core

[DEPRECATED] Search Facebook events by location and proximity.
MIT License
141 stars 56 forks source link

TypeError: Converting circular structure to JSON #22

Closed emilwidlund closed 6 years ago

emilwidlund commented 6 years ago

I'm getting this error with the following syntax. Anyone know if I've messed something up?

es.search({ lat: 59.831834, lng: 17.635795, accessToken: //accessToken }) .then((events) => { console.log(JSON.stringify(events)); }) .catch((err) => { console.error(JSON.stringify(err)); });

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Converting circular structure to JSON

tobilg commented 6 years ago

Can you show the full code and the complete stacktrace?

emilwidlund commented 6 years ago

Here's the code with the accessToken stripped out.

const httpstatus = require('http-status');
const EventSearch = require("facebook-events-by-location-core");
const es = new EventSearch();

module.exports = (app, options) => {
const repo = options.repo;

/*

=================================
GET - GET EVENTS
=================================

*/

app.get('/events', (req, res, next) => {
    if (req.query.longitude && req.query.latitude) {

        es.search({
            lat: parseFloat(req.query.latitude),
            lng: parseFloat(req.query.longitude),
            accessToken: //accessToken
        })
        .then((events) => {
            res.status(httpstatus.OK).json(events);
        })
        .catch((err) => {
            res.status(httpstatus.INTERNAL_SERVER_ERROR).json({errorMessage: 'Something went wrong when searching for nearby events'});
        });

    } else {
        res.status(httpstatus.BAD_REQUEST).json({errorMessage: 'Please specify longitude & latitude coordinates'});
    }

});
}

The thing is that I don't get the error object from the Catch-phase. So the TypeError is all that ends up in my console. I've double-checked and it looks like something is wrong within the lib itself.

tobilg commented 6 years ago

Slightly off-topic, but why don’t you use https://github.com/tobilg/facebook-events-by-location as you’re apparently trying to build an API service?

emilwidlund commented 6 years ago

Mainly because I have a quite big & complex API already setup, and I found that this repo would be the easiest way to get the functionality in.

emilwidlund commented 6 years ago

After some digging, the problem seems to occur on line 124 in eventSearch.js. That success function never executes.

The most recent commit could have caused some issues. https://github.com/tobilg/facebook-events-by-location-core/commit/25c24434d24fb08fdc0dbf0aab73c25b5ad1c5fe

Version 0.7.0 works fine. Downgrading until issue is fixed.

tobilg commented 6 years ago

I actually couldn't find a way to get it to error-ing out... Made some minor tweaks in #23. Tests pass.

tobilg commented 6 years ago

New version 0.8.1 has been published to npm. Please check and close accordingly.

emilwidlund commented 6 years ago

Thanks for such a quick solution. 0.8.1 works fine. Closing issue.