Sorry, that page does not exist', code: 34 - node.js

I'm working on a Node.js app that uses statuses/show/:id to fetch a Tweet object via its ID. However, I keep getting the following error.
"Sorry, that page does not exist', code: 34"
I've been looking for solutions, but they all usually lead back to the GET method being written incorrectly. I've double checked, though, and am pretty sure I'm writing it correctly.
T.get('statuses/show/:id', { id: '759043035355312128' }, function(err, data, response) {
console.log(err);
console.log(data);
});
I've also tried inputting the ID as an int, to no avail.

Did you check if the reference to the object is correct/ try absolute path instead of relative and see if it fixes it.

Related

request.get() - if url not found

So I want to end the request if the user tries to fetch a url which does not work.
This works:
var remote = "https://storage.googleapis.com/ad-system/testfolder/OUTOFAREA.mp3";
var streama = request.get(remote);
however lets say the following mp3 does not exisit
https://storage.googleapis.com/ad-system/testfolder/playme.mp3
When the request.get('https://storage.googleapis.com/ad-system/testfolder/playme.mp3'); tries and fetch the file it will return a 404 error. What I want to do is file not found I want to run res.end();
Any ideas?
you can write like ### request('endpoint url goes here', { json: true }, (err, res, body) => {
if (err) { // keep your business logic here}
}) ######
hope it helps
I doesn't know about this Cloud Storage but even the link isn't accessible so I recommend you check if something is wrong in this service or if you require some special keys or something else to access the content or the service. Then, check your code or use a library that can handle your requirements (if available).
If I found something, I'll let you know :)
EDIT: I can access to https://storage.googleapis.com/ad-system/testfolder/Video/30%20Second%20Timer-0yZcDeVsj_Y.f137.mp4
You could do
app.get("*",(req,res)=> {
res.end()
});
and insert it just before your 404 handler however, I would challenge why that ever might be a good idea. If it's literally so you scan skip checking the return code I really advice you to think twice if thats something you wanna be doing atleast do:
app.get("*",(req,res)=> {
res.status(404)
res.end()
});

Nightwatch-xhr waitForXHR is not returning any results

I am having troubles getting the return back for an XHR call as I need the data from the response.
I am using the library https://github.com/cortexmg/nightwatch-xhr
browser
.url('https://somethincool.com')
.waitForFirstXHR('', 10000, function browserTrigger() {
browser.click('#printStatement');
}, (xhrs) => {
console.log(xhrs[0].responseData);
})
From from what I can tell the first set of quotes after .waitForXHR is a URL pattern. Although I have had no luck figuring out what exactly they are looking for a "URL pattern". I have tried the request URL and some other things, but no luck.
So the issue was that I needed .waitForXHR over .waitForFirstXHR
browser
.waitForXHR('', 5000, function browserTrigger() {
browser.click('#printStatement');
}, (xhrs) => {
console.log(xhrs);
})
Although, it appears there is a bug with getting the responseData :(
The array coming back does not display this data and the question is posted on their github

Accessing response headers using NodeJS

I'm having a problem right now which I can't seem to find a solution to.
I'm using Uservoice's NodeJS framework to send some requests to UserVoice regarding Feedback posts. A problem I've run into are ratelimits so I want to save the header values X-Rate-Limit-Remaining, X-Rate-Limit-Limit and X-Rate-Limit-Reset locally. I've made a function for updating and getting that value and am calling it like this:
var content = "Test"
c.post(`forums/${config.uservoice.forumId}/suggestions/${id}/comments.json`, {
comment: {
text: content
}
}).then(data => {
rl.updateRL(data.headers['X-Rate-Limit-Limit'],data.headers['X-Rate-Limit-Remaining'],data.headers['X-Rate-Limit-Reset'])
When running this code I get the error Cannot read property 'X-Rate-Limit-Limit' of undefined.
This is not a duplicate, I've also tried it lowercase as described here but had no luck either. Thanks for helping out!
EDIT:
The function takes the following parameters:
module.exports = {
updateRL: (lim, rem, res) {SAVING STUFF HERE}
}
It is defined in the file rates.jsand is imported in the above file as const rl = require('../rates').

How to get Express to return the object I just deleted in MongoDB

Feel free to let me know if this isn't a common practice - I'm a fairly new programmer - but I thought I've seen APIs in the past that, when you submit a DELETE request to a resource (/todo/1234), some servers will return the object you just deleted in the response. Is that a thing? If so, I'd be interested in learning how to do it. Here's what I have:
.delete(function (req, res) {
Todo.findById(req.params.todoId).remove(function (err) {
if (err) res.status(500).send(err);
res.send("Todo item successfully deleted");
});
});
This code does delete the item, but I would like to return the item that got deleted in the response instead of a string message. If that's a normal/okay thing to do. If it isn't normal or okay for some reason, please let me know why and I'll just move on. Or perhaps there's a more common way.
This is what I found in the [RFC 7231 docs][1]:
If a DELETE method is successfully applied, the origin server SHOULD
send a 202 (Accepted) status code if the action will likely succeed
but has not yet been enacted, a 204 (No Content) status code if the
action has been enacted and no further information is to be supplied,
or a 200 (OK) status code if the action has been enacted and the
response message includes a representation describing the status.
I'm having a hard time interpreting what the 200 response means - is it only kosher to send a string message (Success!) or an object containing a message attribute ({message: "Success!"})? Or can you do whatever you want there? What's the best practice in Express using Mongoose?
Thanks in advance for the help, and sorry for my noobness with HTTP stuff.
[1]: https://www.rfc-editor.org/rfc/rfc7231#section-4.3.5
You should use findOneAndRemove! Something like:
Todo.findOneAndremove({ id: req.params.todoId }, function( error, doc, result) {
// it will be already removed, but doc is what you need:
if (err) res.status(500).send(err);
res.send(doc.id);
});

getting OEMBED object to return instead of undefined using Twit for Node

So i am using Twit https://github.com/ttezel/twit for Node
i would like to get the OEMBED code from the twitter 1.1 api , but it does not seem to work.
twit.get('statuses/oembed', { id: 133640144317198338 }, function (err, data, response) {
console.log(data);
console.log(err);
})
So I just keep getting undefined returned back to me, the url pattern seems correct but i do not know why it is not working.
Here is the error that is logged
{ [Error: Sorry, that page does not exist]
message: 'Sorry, that page does not exist',
statusCode: 404,
code: 34,
allErrors: [ { message: 'Sorry, that page does not exist', code: 34 } ],
twitterReply: '{"errors":[{"message":"Sorry, that page does not exist","code":34}]}' }
I am able to retrieve statues and pretty much everything else, but oembed will not work.
Any HELP would be great
Here is the link to OEMBED api for twitter https://api.twitter.com/1.1/statuses/oembed.json?id=240192632003911681
Wrap some quotes around your Tweet ID. I ran into this because I was feeding in a status's id, not id_str.
Insert some quotes around your Tweet ID.

Resources