You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Double callback when using multiple custom post types? #84
Hi!
If I do this wp.posts().type(['cityreport','place']).get(function (err, data) {
I get a console error "double callback", and then a "syntax error". Also my error callback gets called.
The URL called does include the right data, but parsing it fails? It is valid JSON.
Or am I doing something wrong?
I did some more debugging, and if I copy the content for the requested URL to a static page, the library doesn't crash. So I suspect it has something to do with headers, or encodings.
The error I get is: double callback! ERR [SyntaxError: Unexpected token <]
Any ideas how to fix this? Not being able to request multiple post types is really frustrating, especially since it is in one of the example uses.
Hey @PanManAms, sorry I missed this issue when you opened it last week! Off the top of my head I'm not sure what might be going on, but I'll try to look into it this weekend. Multiple types is definitely something we want to support.
Thanks for looking into it, it's kind of critical for us. The strange part is that the URL's get made correctly, its in parsing the result that it breaks. Let me know if an example url helps (and how I can privately send it). I did test it with wp.root (and wp.url) and both have the same behaviour. Thnx!
While I am not yet able to reproduce the issue described (double callback!), I am seeing an issue where superagent is transforming the (already-formatted) type[]=type1&type[]=type2 portion of the URL into type[][0]=type1&type[][1]=type2. This results in the following error:
http://[test site url]/wp-json/posts?filter%5Bcity%5D=cityname&type%5B%5D=event&type%5B%5D=evttype
{ [Error: cannot GET /wp-json/posts?filter%5Bcity%5D=cityname&type%5B%5D[0]=event&type%5B%5D[1]=evttype (403)]
status: 403,
method: 'GET',
path: '/wp-json/posts?filter%5Bcity%5D=cityname&type%5B%5D[0]=event&type%5B%5D[1]=evttype' }
This can certainly be avoided by removing the [] around the type property, since superagent evidently inserts the array syntax and indices itself; however, we will also be reevaluating whether we're using the right request library, since this is not intuitive behavior.
Btw, for now I have worked around it by using request: Building the data with wordpress-rest-api and then requesting the url (and returning the data) with request. Might be helpful for others. Still should work tho :)
HI. Unfortunately this is still occurring. I just did an NPM update, but unfortunately still get the same double callback.
I'm not sure this is directly related to #89.
I have been able to work around this, by using this library to build the url, and calling _renderURI() and requesting that url with the 'request' package.
I can't reopen the issue here, but at my end it is still broken.
Regards,
PanMan.
@PanManAms The issue will still occur if you use the wp.url() method, because the array indices will not be present in the string; e.g., wp.url('yoururl/wp-json/posts?type[]=type1&type[]=type2') will fail, but wp.url('yoururl/wp-json/posts?type[0]=type1&type[1]=type2') should succeed. Additionally, any URL created with the URL builder methods such as posts() should succeed.
Activity
PanMan commentedon Nov 14, 2014
I did some more debugging, and if I copy the content for the requested URL to a static page, the library doesn't crash. So I suspect it has something to do with headers, or encodings.
The error I get is:
double callback! ERR [SyntaxError: Unexpected token <]Any ideas how to fix this? Not being able to request multiple post types is really frustrating, especially since it is in one of the example uses.
kadamwhite commentedon Nov 14, 2014
Hey @PanManAms, sorry I missed this issue when you opened it last week! Off the top of my head I'm not sure what might be going on, but I'll try to look into it this weekend. Multiple types is definitely something we want to support.
PanMan commentedon Nov 14, 2014
Thanks for looking into it, it's kind of critical for us. The strange part is that the URL's get made correctly, its in parsing the result that it breaks. Let me know if an example url helps (and how I can privately send it). I did test it with wp.root (and wp.url) and both have the same behaviour. Thnx!
kadamwhite commentedon Nov 14, 2014
An example URI would help; let me know how you'd best prefer to send it my way.
PanMan commentedon Nov 14, 2014
if you follow me back on twitter (@PanMan ) I'll DM it. I couldn't find your email on your website?
kadamwhite commentedon Nov 18, 2014
While I am not yet able to reproduce the issue described (
double callback!), I am seeing an issue where superagent is transforming the (already-formatted)type[]=type1&type[]=type2portion of the URL intotype[][0]=type1&type[][1]=type2. This results in the following error:This can certainly be avoided by removing the
[]around the type property, since superagent evidently inserts the array syntax and indices itself; however, we will also be reevaluating whether we're using the right request library, since this is not intuitive behavior.PanMan commentedon Nov 21, 2014
Btw, for now I have worked around it by using request: Building the data with wordpress-rest-api and then requesting the url (and returning the data) with request. Might be helpful for others. Still should work tho :)
kadamwhite commentedon Dec 4, 2014
@PanManAms this should be resolved by 0.3.1, released this morning: try updating the package and let me know if the issue is still occurring!
PanMan commentedon Dec 4, 2014
HI. Unfortunately this is still occurring. I just did an NPM update, but unfortunately still get the same double callback.
I'm not sure this is directly related to #89.
I have been able to work around this, by using this library to build the url, and calling _renderURI() and requesting that url with the 'request' package.
I can't reopen the issue here, but at my end it is still broken.
Regards,
PanMan.
PanMan commentedon Dec 4, 2014
Hi.
I created this minimal test case, which at my end still crashes:
Output I get is:
I tested on 2 different machines here, both crash.
kadamwhite commentedon Dec 4, 2014
@PanManAms The issue will still occur if you use the
wp.url()method, because the array indices will not be present in the string; e.g.,wp.url('yoururl/wp-json/posts?type[]=type1&type[]=type2')will fail, butwp.url('yoururl/wp-json/posts?type[0]=type1&type[1]=type2')should succeed. Additionally, any URL created with the URL builder methods such asposts()should succeed.PanMan commentedon Dec 4, 2014
Hmmm, you are right, it IS fixed now...
kadamwhite commentedon Dec 4, 2014
Glad to hear it! Let me know if you find any other issues.