urlfetch for an API call but can’t seem to properly catch the error when the status is 400/404, or if the query yields nothing/error. Responses with status code 200 work fine.
Nightbot always returns
Right-hand side of 'instanceof' is not an object. Tried try/catch, still no go. Am I doing something wrong?
Stuff the urlfetch reponse in a string and check before doing anything else whether it contains any http error or the urlfetcher connection has failed. You can build upon the following code to make individual responses for specific http errors.
$(eval const fetchResult = `$(urlfetch https://customapi.com)`; fetchResult.includes(`Remote Server`) || fetchResult === `Error Connecting To Remote Server` ? `some fallback message` : fetchResult)
Thanks, that’s awesome! Stringifying
urlfetch's result helped! Had to use
json for my query. Been wondering what the exact error message Nightbot returns for scenarios like this and this finally answered that question.
Also, the 400-character limit is fixed despite Twitch chat’s 500-character limit? I am pulling long texts from an API, some with 600+ characters long. Would be an awesome feature for Nightbot to have a break up and continue the response if max character is reached. Maybe in the future?
I wrote a little script for sending multiple messages in a single command. Go to https://pastebin.com and paste a series of up to 6 texts separated by backticks. The first text must be up to 200 characters. Subsequent texts must be up to 400 characters. See https://pastebin.com/GUZcy5tP for an example. Then paste the raw paste url into the following command response:
$(urlfetch https://rokbot.xyz/smm.php?msg=$(urlfetch json https://pastebin.com/raw/FOOrBARj))
Man, this is awesome! Perfect for what I wanna do. I’m trying to create a command for pulling up info of cards for a card game. I’ll play with this today. Thanks!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.