pogodevorg / pgoapi-go

Unofficial PokemonGO API in Go
https://pogodev.org
MIT License
65 stars 29 forks source link

Occasional "The profile needs to be authorized" error from session.GetPlayer() and session.getPlayerMap() #13

Closed moddyz closed 8 years ago

moddyz commented 8 years ago

Reproduction (basically run the example code provided on README.md):

  1. Create new session with provider
  2. Init session
  3. Call either GetPlayer / GetPlayerMap or both

About half the time I'm getting the error "The profile needs to be authorized" returning from those method calls in 3.

The provider is definitely valid because the other half the time the call returns the player data / map data successfully.

Any ideas? Is there any more info I could provide?

zeevallin commented 8 years ago

I've noticed this as well, you can get the error code requiring a person to re-authorize despite giving you a valid set of map objects or player data. You should be able to use it despite the error being thrown.

Not quite sure how to architect this, got any ideas?

moddyz commented 8 years ago

Ah I just assumed that because a error was returned that the data part was nil. I can probably handle this on the client side and just ignore the error if data is not nil. Maybe as a start it would be helpful add a comment/docstring to highlight of this potential combination of return values.

I'm still a bit new to Go coming from Python - is error type checking a 'thing'? Could we check that if the data is valid, and the error type is the 'The profile needs to be authorized', then simply log it as a debug/warning message and return nil as error?

zeevallin commented 8 years ago

@moddyz Something like this:

switch t := err.(type) {
  default:
    // do something
  case *MyErrorType:
    // do something else
}
moddyz commented 8 years ago

Nice! Good to know. Cheers

zeevallin commented 8 years ago

So, since we've figured out what this error is, it happens every time the client needs to refresh their API endpoint. I've corrected the name of the error, but I'm going to also add a handler for it to automatically refresh.