Throw exceptions if token generation fails.

This is instead of returning `false`, which confuses the `JsonView` class and subsequently outputs an error when trying to `json_encode` that value.

Ping @akrabat too as I'm not sure if this will affect web2's handling of any failures?

Also added some tests for the token generation - these assume the dummy data from the data generator is present; I can't remember if this is the case on jenkins or not...