Raising an InvalidTokenException if invalid token

I'm really, really not sure I'm doing this right; but I keep having that "invalid access token" issue, and I would just like to be able to sign out automatically when it happens.
But to do that, I need to know when it happens, and I figured the cleaner way to do it was to do it was to raise it as soon as the response comes back.
But I'm using a string comparison to do it; that's what makes me think there's probably a better way to do it.
Let me know.