Parsing nested JSON from aws SNS message - javascript

I'm having trouble returning errorMessage from this nested JSON response I get from an aws SNS message. Part of the problem, I think, is the weird spaces and formatting this is returned in. I parsed the whole thing once to get message which I'm able to return values like executionIdfrom, but JSON.parse(message.errorData) already throws me an error before I can continue downward to -> Cause -> errorMessage.
{"executionId":"<<ARN REDACTED>>","stateName":"9b44bafc-d542-4533-8091-5c9a2bfd9983","startTime":"2022-04-07T16:20:59.350Z","sourceStepFunction":"<<REDACTED>>","errorData":{"Error":"Error","Cause":"{\"errorType\":\"Error\",\"errorMessage\":\"Request failed with status code 400\",\"trace\":[\"Error: Request failed with status code 400\",\" at e.exports (/var/task/index.js:2:69443)\",\" at e.exports (/var/task/index.js:2:71859)\",\" at IncomingMessage.<anonymous> (/var/task/index.js:2:62409)\",\" at IncomingMessage.emit (events.js:412:35)\",\" at IncomingMessage.emit (domain.js:475:12)\",\" at endReadableNT (internal/streams/readable.js:1334:12)\",\" at processTicksAndRejections (internal/process/task_queues.js:82:21)\"]}"}}

Related

Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.5.3)

I am new to this space and in the process of learning Solidity and Javascript. So please bear with me.
I was executing simple node script and stumbled across this error.
Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.5.3)
at Logger.makeError (/Users/code/ethers_examples/node_modules/#ethersproject/logger/lib/index.js:199:21)
at Logger.throwError (/Users/code/ethers_examples/node_modules/#ethersproject/logger/lib/index.js:208:20)
at JsonRpcProvider. (/Users/code/ethers_examples/node_modules/#ethersproject/providers/lib/json-rpc-provider.js:517:54)
at step (/Users/code/ethers_examples/node_modules/#ethersproject/providers/lib/json-rpc-provider.js:48:23)
at Object.throw (/Users/code/ethers_examples/node_modules/#ethersproject/providers/lib/json-rpc-provider.js:29:53)
at rejected (/Users/code/ethers_examples/node_modules/#ethersproject/providers/lib/json-rpc-provider.js:21:65)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
reason: 'could not detect network',
code: 'NETWORK_ERROR',
event: 'noNetwork'
Any fix to this will be appreciated.
Thanks!

DiscordJS Error POST-FAILED Code: 50001 remove error message

im owning a Discord bot for music and stuff.
My console always gets spammed full with this message:
20:2:2022 - 17:22 | Info: [Slash Command]: [POST-FAILED] Guild 945348402374385736, Command: youtube
DiscordAPIError: Missing Access
at RequestHandler.execute (/home/m9mo/node_modules/discord.js/src/rest/RequestHandler.js:154:13)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async RequestHandler.push (/home/m9mo/node_modules/discord.js/src/rest/RequestHandler.js:39:14)
at async /home/m9mo/util/RegisterSlashCommands.js:36:9 {
method: 'post',
path: '/applications/895283932252241940/guilds/945348402374385736/commands',
code: 50001,
httpStatus: 403
}
I know the reason for this error but some people are creating their own invite link using the id of the bot...
Is there any way to disable this message?
You could try finding the error code (In this case 50001) of that specific error, then when you receive an error, stop it from being logged. You can find all the relevant error codes here: https://discord.com/developers/docs/topics/opcodes-and-status-codes#json-json-error-codes
You might also want to consider sending some kind of message like I'm missing permission to do...

MetaMask Ether Faucet

Please anyone can tell what should I do? I get this error:
Error: 500 {"error":"[ethjs-query] while formatting outputs from RPC '{\"value\":{\"code\":-32603,\"message\":\"Too Many Requests\",\"data\":{\"originalError\":{}},\"stack\":\"Error: Too Many Requests\\n at eval (/www/node_modules/web3-provider-engine/subproviders/rpc.js:52:23)\\n at Request.eval [as _callback] (/www/node_modules/web3-provider-engine/subproviders/rpc.js:54:11)\\n at Request.self.callback (/www/node_modules/request/request.js:186:22)\\n at Request.emit (events.js:315:20)\\n at Request.eval (/www/node_modules/request/request.js:1155:10)\\n at Request.emit (events.js:315:20)\\n at IncomingMessage.eval (/www/node_modules/request/request.js:1077:12)\\n at Object.onceWrapper (events.js:421:28)\\n at IncomingMessage.emit (events.js:327:22)\\n at endReadableNT (internal/streams/readable.js:1327:12)\"}}'"}
I think you have sent too many requests in a short period of time as it hints in the response property called message "message": "Too Many Requests". Now rate limits cooldown time differs for every service out there, but you can try to wait for a couple of minutes and try again, if you still receive you might have to wait for an hour, a day and so on.

Tests with Probot API from GitHub and Smee failing to accept payload?

I'm posting some sample data to my Smee endpoint and I am also running a local instance of my ProBot app. I get a bad request in my bot logs and I see this is the Smee response:
{ Error: cannot POST / (400)
at Response.toError (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/response.js:94:15)
at ResponseBase._setStatusProperties (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/response-base.js:123:16)
at new Response (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/response.js:41:8)
at Request._emitResponse (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/index.js:752:20)
at IncomingMessage.parser (/usr/local/lib/node_modules/smee-client/node_modules/superagent/lib/node/index.js:916:38)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1055:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
status: 400,
text: 'Required headers missing: x-github-event, x-github-delivery',
method: 'POST',
path: '/' },
How can I get these header values to test with in my app? Not sure if it's me, but the documentation doesn't note this anywhere
I used https://www.freeformatter.com/hmac-generator.html#ad-output to throw in the payload as the body and my secret and the hash was valid!

Scraping request run through Heroku Scheduler (Node.js) fails half the time

I set up a very basic web scraper to check stock of a specific item on Costco.com for my grandfather. It's working great locally, but when I run it through Heroku it fails (seemingly 50% of the time). Here's the code for the scraper
const task = () => {
// toggle so doesn't send message multiple times if continuously available
let alreadyAvailable = false;
let url = 'http://www.costco.com/Kirkland-Signature-Four-Piece-Urethane-Cover-Golf-Ball,-2-dozen.product.100310467.html';
request(url, function(error, response, html){
let $ = cheerio.load(html);
if(error){
throw new Error(error);
}
if ( $('#product-page #product-details #ctas #add-to-cart input[type="button"]')['0'].attribs.value === 'Out of Stock') {
alreadyAvailable = false;
console.log("still out of stock");
} else {
if (alreadyAvailable === false) {
sendMessage();
alreadyAvailable = true;
}
}
});
};
and here are the logs
2016-12-25T03:48:39.675549+00:00 heroku[scheduler.5440]: Starting process with command `node scraper.js`
2016-12-25T03:48:40.262503+00:00 heroku[scheduler.5440]: State changed from starting to up
2016-12-25T03:48:41.509416+00:00 app[scheduler.5440]: /app/scraper.js:34
2016-12-25T03:48:41.509432+00:00 app[scheduler.5440]: if ( $('#product-page #product-details #ctas #add-to-cart input[type="button"]')['0'].attribs.value === 'Out of Stock') {
2016-12-25T03:48:41.509433+00:00 app[scheduler.5440]: ^
2016-12-25T03:48:41.509433+00:00 app[scheduler.5440]:
2016-12-25T03:48:41.509434+00:00 app[scheduler.5440]: TypeError: Cannot read property 'attribs' of undefined
2016-12-25T03:48:41.509434+00:00 app[scheduler.5440]: at Request._callback (/app/scraper.js:34:90)
2016-12-25T03:48:41.509435+00:00 app[scheduler.5440]: at Request.self.callback (/app/node_modules/request/request.js:186:22)
2016-12-25T03:48:41.509436+00:00 app[scheduler.5440]: at emitTwo (events.js:106:13)
2016-12-25T03:48:41.509436+00:00 app[scheduler.5440]: at Request.emit (events.js:191:7)
2016-12-25T03:48:41.509436+00:00 app[scheduler.5440]: at Request.<anonymous> (/app/node_modules/request/request.js:1081:10)
2016-12-25T03:48:41.509437+00:00 app[scheduler.5440]: at emitOne (events.js:96:13)
2016-12-25T03:48:41.509437+00:00 app[scheduler.5440]: at Request.emit (events.js:188:7)
2016-12-25T03:48:41.509438+00:00 app[scheduler.5440]: at IncomingMessage.<anonymous> (/app/node_modules/request/request.js:1001:12)
2016-12-25T03:48:41.509438+00:00 app[scheduler.5440]: at IncomingMessage.g (events.js:291:16)
2016-12-25T03:48:41.509439+00:00 app[scheduler.5440]: at emitNone (events.js:91:20)
2016-12-25T03:48:41.509439+00:00 app[scheduler.5440]: at IncomingMessage.emit (events.js:185:7)
2016-12-25T03:48:41.509439+00:00 app[scheduler.5440]: at endReadableNT (_stream_readable.js:974:12)
2016-12-25T03:48:41.509440+00:00 app[scheduler.5440]: at _combinedTickCallback (internal/process/next_tick.js:74:11)
2016-12-25T03:48:41.509440+00:00 app[scheduler.5440]: at process._tickCallback (internal/process/next_tick.js:98:9)
2016-12-25T03:48:41.560539+00:00 heroku[scheduler.5440]: State changed from up to complete
2016-12-25T03:48:41.550655+00:00 heroku[scheduler.5440]: Process exited with status 1
2016-12-25T03:58:42.438807+00:00 app[api]: Starting process with command `node scraper.js` by user scheduler#addons.heroku.com
2016-12-25T03:58:43.701468+00:00 heroku[scheduler.5038]: Starting process with command `node scraper.js`
2016-12-25T03:58:44.312279+00:00 heroku[scheduler.5038]: State changed from starting to up
2016-12-25T03:58:45.769564+00:00 app[scheduler.5038]: still out of stock
2016-12-25T03:58:45.827867+00:00 heroku[scheduler.5038]: State changed from up to complete
2016-12-25T03:58:45.814921+00:00 heroku[scheduler.5038]: Process exited with status 0
You can see that sometimes I get the console log inside of the if-block and others I get a type error because it's trying to read attributes from an html element that don't exist. I was thinking that this might be a async issue, but I'm not sure how to go about fixing it. I assumed Request wasn't running the callback until it got all the html.
The problem here is what Costco's website is returning.
Your code is failing when parsing the DOM via Cheerio. What this means in your case is that the particular HTML you're attempting to scrape doesn't actually exist (that's what the error is saying).
This could be caused by a few possible things:
Costco is rendering a DIFFERENT page than what you expect (maybe it thinks you're a bot, or is doing some throttling).
You are receiving a redirect or some other sort of non-error HTTP status code, and the HTML you're looking for doesn't exist there.
Costco's website changes the HTML dynamically to prevent people from scraping.
What I would do if I were you is this:
Have your process log all the page's HTML when the task runs.
The next time your process fails, copy the HTML from the Heroku logs into a local editor, and see what it returned.
I'm willing to bet you will be surprised =)

Categories

Resources