node-wpapi
node-wpapi copied to clipboard
Is it just me or the error messages are awful?
For example, trying to post on a multisite that doesn't exist gives the error:
Not Found
at Request.Object.<anonymous>.Request.callback (node_modules/superagent/lib/node/index.js:804:15)
at IncomingMessage.parser (node_modules/superagent/lib/node/index.js:1036:18)
I've also gotten completely useless JSON.parse errors with no useful trace though I don't remember how to reproduce. I'm using Jest to catch and log errors, maybe it's parsing them wrong or something.
Hi,
I am in a similar situation: I have an error but I don't know how to debug this because no further information is provided.
Error: Not Found at Request.callback (/app/node_modules/wpapi/node_modules/superagent/lib/node/index.js:804:15) at /app/node_modules/wpapi/node_modules/superagent/lib/node/index.js:1036:18
The file and line where the error is generated are the same.
--Update-- In my case, this was generating from the pagination code snippet in the documentation (https://github.com/WP-API/node-wpapi#collection-pagination) which I was using as it is in my project. I rewrote that loop from scratch with some different logic and the issue is gone.
@countfak If you have an updated pagination snippet, could you share that as a docs PR (or respond with it here?) If we're sharing incorrect example code, we should fix that
Hi,
I'm not saying that the example code is wrong, it's been working fine but at some point it started to throw that error. I still don't know why, maybe I changed something and it was my fault, sorry I don't remember.
This is how I fetch all posts now. This is working fine in my case and the error is gone.
let posts = [],
postsBatch = [],
page = 1;
do {
try {
postsBatch = await wp.posts().perPage(100).page(page);
} catch (error) {
console.error(error);
}
posts = posts.concat(postsBatch);
page++;
} while (postsBatch && postsBatch._paging && page <= postsBatch._paging.totalPages);
console.log(posts);
Have same issue, in my case problem was with uploaded media, wordpress has limit 8mb for image.