pokeapi
pokeapi copied to clipboard
Error formating
Hello! As you might know, pokemon legends are out. Wich can cause not found errors in the db. But instead of formating it in json you format it in plain html. Why is this? As this can break alot of code . My request is if you guys could kindly change up that to json. Thank you! Zakaria Aourzag
Can you post an example?
If you go to https://pokeapi.co/api/v2/pokemon/900 which is from legends archeus, it'll return: "Not Found". In a non json format. Which gives you an error if you use most like code requests it'll error out.
PokeAPI retrieves 404s when no resources are found. Why not verify the http status code before parsing the response?
It might be because of the json parser I use, but it just goes SyntaxError: Unexpected token N in JSON at position 0
Hi zaourzag,
I think what Kronopt is saying is that you should verify the http status first. If the status is 200, only then try to parse the json response.
The logic would be something like this:
if http_status_code == 200:
parse_json(json_data)
else:
return pokemon_doesnt_exist error
Hi yes, all the proposed solutions are valid. But I like the idea of returning JSON formatted error codes if the resource is missing.
In the meantime, check the status code before attempting to read the returned data.
https://jasonwatmore.com/post/2021/10/09/fetch-error-handling-for-failed-http-responses-and-network-errors#:~:text=The%20fetch()%20function%20will,ourselves%20by%20calling%20return%20Promise.
Will do, but it was just more of an inconsistency I found lol. (For the record, I use a node http lib based off of centra and undici)
I mean I tried to find where the 404 error code is. I'm familiar with python but I'm not a master in it lol. Nodejs and Express are more my jam :P