Comments (9)
If you place it inside the try
block, the whole try statement will run from start-to-finish unless an error occurs. So you'll be able to catch 404's, 500's, etc of both Summoner
and CurrentGame
. Not sure about the scoping part, but IMO if the logic is "combined", then put it all in one try
block.
I would put it in there personally, unless you want specific error-handling on a case-by-case basis.
from kayn.
Ohhh, I haven't been reading carefully. you can try this:
const nombre = args.slice([1]).join(' ');
const nombreUrl = nombre.replace(/\s/g, "%20").toLowerCase();
let summoner = null;
try {
summoner = await kayn.Summoner.by.name(nombre);
} catch (ex) {
if (ex.statusCode == 404) game = null;
else throw new Error("completely broken");
}
let game = null;
try {
game = await kayn.CurrentGame.by.summonerID(summoner.id) // awaiting doesn't solve it
} catch (ex) {
if (ex.statusCode == 404) game = null;
else throw new Error("completely broken");
}
console.log(summoner, game)
Basically, if there's a 404, just reassign null
, otherwise if it's some other error that mean something really bad happened (assuming retries are on), so just throw.
from kayn.
You forgot to await
kayn.CurrentGame.by.summonerID(summoner.id)
as well. All of kayn
's requests return promises that must be awaited.
from kayn.
Same result.
(node:8832) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'then' of undefined
at Request.catch.callback [as catch] (C:\Users\viks\Desktop\basil\node_modules\kayn\dist\lib\RequestClient\Request.js:67:49)
at Object.execute (C:\Users\viks\Desktop\basil\comandos\riotAPI.js:46:71)
at Client.client.on (C:\Users\viks\Desktop\basil\basil.js:55:11)
at Client.emit (events.js:203:15)
at MessageCreateHandler.handle (C:\Users\viks\Desktop\basil\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Users\viks\Desktop\basil\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (C:\Users\viks\Desktop\basil\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\Users\viks\Desktop\basil\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\Users\viks\Desktop\basil\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:198:13)
at Receiver.receiverOnMessage (C:\Users\viks\Desktop\basil\node_modules\ws\lib\websocket.js:789:20)
at Receiver.emit (events.js:198:13)
at Receiver.dataMessage (C:\Users\viks\Desktop\basil\node_modules\ws\lib\receiver.js:422:14)
at Receiver.getData (C:\Users\viks\Desktop\basil\node_modules\ws\lib\receiver.js:352:17)
at Receiver.startLoop (C:\Users\viks\Desktop\basil\node_modules\ws\lib\receiver.js:138:22)
at Receiver._write (C:\Users\viks\Desktop\basil\node_modules\ws\lib\receiver.js:74:10)
at doWrite (_stream_writable.js:415:12)
at writeOrBuffer (_stream_writable.js:399:5)
at Receiver.Writable.write (_stream_writable.js:299:11)
at TLSSocket.socketOnData (C:\Users\viks\Desktop\basil\node_modules\ws\lib\websocket.js:864:35)
at TLSSocket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
from kayn.
Hmm, I have a feeling that
const summoner = await kayn.Summoner.by.name(nombre) // this line
let game = await kayn.CurrentGame.by.summonerID(summoner.id)
The commented line may be returning an error.
You can try this:
try {
const summoner = await kayn.Summoner.by.name(nombre)
let game = await kayn.CurrentGame.by.summonerID(summoner.id) // awaiting doesn't solve it
console.log(typeof(game));
} catch (error) {
console.log(error)
}
to see what the error is.
from kayn.
{ statusCode: 404,
url:
'https://euw1.api.riotgames.com/lol/spectator/v4/active-games/by-summoner/omitted-the-ID-on-github-comment',
error:
{ name: 'StatusCodeError',
Alright! This worked just fine, now I can reasign with !game.statusCode === 200
. Must I place kayn.CurrentGame
inside the Try block, or any call that may return a 404? does it scope it?
Thanks for your help, this saved my day!
from kayn.
Looks like there's no way to redefine the variable if there is no current game for the summoner, or at least that I'm capable of. Thanks for your help anyway! :)
from kayn.
O M G
So I can actually reasign if the variable is declared outside the try{} catch {}
block in the first place?!
Yes! This returns the current game object if there is one and allows me to reasign game to "No current games"
if it's value is null due to ex.statusCode == 404
. No bugs here, just an ES6 noob.
from kayn.
it's okay haha, good luck! I didn't read the question properly so my first answer or 2 were not actually answering the question properly
from kayn.
Related Issues (20)
- Grab Spell by his id/key
- Match-V5 Support HOT 1
- /typings/index.d.ts(293,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. HOT 3
- v0.9.4 rate limiter may be broken HOT 2
- summoner/v3 endpoint returning forbidden HOT 2
- positional rank endpoints HOT 1
- Positional Rank Endpoints HOT 1
- Positional Ranking Deprecation HOT 2
- Does Kayn respect custom rate limit? HOT 2
- Minor unnecessary import in index.d.ts HOT 5
- RunesReforged Optional Versions HOT 3
- Current LeaguePositions issue HOT 1
- Make the API host configurable HOT 3
- Very slow requests ? HOT 4
- v0.10.1 release doesn't include a prebuilt dist/ directory HOT 2
- RunesReforged bug HOT 2
- Error: Can't resolve 'fs' in 'D:\Programmierung\my-app\node_modules\dotenv\lib' HOT 9
- TFT Ratelimit (Research)
- trying to use diffrent region the default that was placed in the kayn configuration
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kayn.