Skip to content

Commit 8dcef66

Browse files
committed
Making sure that ReCodEx API call failures caused by invalid token are propagated to frontend and invalid token failure (so the logout is triggered).
1 parent 9f64c24 commit 8dcef66

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

app/helpers/Recodex/RecodexApiHelper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Exceptions\ConfigException;
66
use App\Exceptions\RecodexApiException;
7+
use App\Exceptions\InvalidAccessTokenException;
78
use App\Model\Entity\SisScheduleEvent;
89
use App\Model\Entity\User;
910
use Nette;
@@ -129,10 +130,15 @@ private function prepareOptions(array $query = [], $body = null, array $headers
129130
* Decode and verify JSON body.
130131
* @return array|string|int|bool|null decoded JSON response
131132
* @throws RecodexApiException
133+
* @throws InvalidAccessTokenException
132134
*/
133135
private function processJsonBody($response)
134136
{
135137
$code = $response->getStatusCode();
138+
if ($code === 401) { // unauthorized, token is probably invalid
139+
throw new InvalidAccessTokenException("Unauthorized request to ReCodEx API. Token is probably invalid.");
140+
}
141+
136142
if ($code !== 200) {
137143
Debugger::log("HTTP request to ReCodEx API failed (response $code).", Debugger::DEBUG);
138144
throw new RecodexApiException("HTTP request failed (response $code).");

app/presenters/LoginPresenter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use App\Security\Roles;
1515
use App\Security\TokenScope;
1616
use Nette\Security\AuthenticationException;
17-
use Exception;
1817

1918
/**
2019
* Endpoints used to log a user in

0 commit comments

Comments
 (0)