Maybe instead of this new function which do almost nothing just replace this code with:
```php
if (isset($response['error']) || isset($error['message'])) {
    throw new AuthenticationException(sprintf('OAuth error: "%s"', isset($error['message']) ? $error['message'] : $response['error'])); 
}