kevinohashi / php-riot-api

PHP Wrapper for Riot Games API
MIT License
76 stars 40 forks source link

error 500 when searching for a non-existent summoner #53

Closed rensknoors closed 8 years ago

rensknoors commented 8 years ago

Thanks again for your work,

I've run into some trouble again. Whenever i try to search the summonerID from a non-existent summoner name, the request reaches a error 500 page.

The problem now is that I can't get rid of this error. I tried error handling already (try catch and a normal if statement) but it doesn't work because nothing is stored inside the variable i want to store the ID in.

This part of code is where it all goes wrong

// summonerName -> summonerID
$summID = $test->getSummonerId($summName);
$_SESSION['summonerID'] = $summID;

I got this error when i enabled display errors:

Fatal error: Uncaught exception 'Exception' with message 'NOT_FOUND' in /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/php-riot-api.php:325 Stack trace: #0 /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/php-riot-api.php(237): riotapi->request('https://{region...') #1 /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/php-riot-api.php(194): riotapi->getSummonerByName('nzczjdscjkckj') #2 /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/getData.php(20): riotapi->getSummonerId('nzczjdscjkckj') #3 /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/login.php(43): include('/home/i313451/d...') #4 {main} thrown in /home/i313451/domains/i313451.iris.fhict.nl/public_html/wp31/League/php-riot-api.php on line 325

I hope you get more out of it then I did.

kevinohashi commented 8 years ago

That is very strange because it seems like it's finding the error properly. NOT_FOUND is 404 error code response from the API. Which is what you would expect from a non-existent summoner. The 500 error is an error from your PHP server, meaning something went wrong.

My guess is you didn't wrap your call in a try catch block? Look at the example https://github.com/kevinohashi/php-riot-api/blob/master/testing.php

It seems you're not catching the exception the API throws when a summoner isn't found. If you catch that, I think your code will work just fine.

rensknoors commented 8 years ago

You were right, I just made a stupid mistake with the try catch. I forgot the (Exception $e) after catch. Guess I was just tired :(

kevinohashi commented 8 years ago

No problem. Happens to the best of us :)