Skip to content

Commit bbbf6e2

Browse files
committed
📖
1 parent 17ce1e2 commit bbbf6e2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/Usage/Authorization.md

+22
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,25 @@ $request = $requestFactory->createRequest('GET', 'https://api.github.com/user')
116116
// authenticated request
117117
$response = $provider->sendRequest($request); // -> ResponseInterface instance
118118
```
119+
120+
You might want to wrap the API call in a try/catch block that catches the `InvalidAccessTokenException` (expired token, unable to refresh)
121+
or its parent `UnauthorizedAccessException` (general HTTP error: 400, 401, 403) and decide what to do in that case:
122+
123+
```php
124+
try{
125+
$response = $provider->sendRequest($request);
126+
}
127+
catch(Throwable $e){
128+
129+
if($e instanceof InvalidAccessTokenException){
130+
// redirect to (re-) authorization
131+
header('Location: '.$provider->getAuthorizationURL($params, $scopes));
132+
}
133+
elseif($e instanceof UnauthorizedAccessException){
134+
// handle http error
135+
}
136+
137+
// something else went horribly wrong
138+
throw $e;
139+
}
140+
```

0 commit comments

Comments
 (0)