mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-10 02:45:22 +02:00
Fix strange error in pokedex fetch
This commit is contained in:
@@ -6,6 +6,7 @@ const missingno = require('../../assets/json/missingno');
|
||||
module.exports = class PokemonStore extends Collection {
|
||||
async fetch(query) {
|
||||
query = encodeURIComponent(query.toLowerCase().replace(/ /g, '-').replace(/[^a-zA-Z0-9-]/g, ''));
|
||||
if (!query) return null;
|
||||
const num = Number.parseInt(query, 10);
|
||||
if (this.has(num)) return this.get(num);
|
||||
const found = this.find(pokemon => pokemon.slug === query);
|
||||
@@ -15,9 +16,13 @@ module.exports = class PokemonStore extends Collection {
|
||||
this.set(pokemon.id, pokemon);
|
||||
return pokemon;
|
||||
}
|
||||
const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon-species/${query}/`);
|
||||
const pokemon = new Pokemon(body);
|
||||
this.set(pokemon.id, pokemon);
|
||||
return pokemon;
|
||||
try {
|
||||
const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon-species/${query}/`);
|
||||
const pokemon = new Pokemon(body);
|
||||
this.set(pokemon.id, pokemon);
|
||||
return pokemon;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user