Mas logs y middlewares en Guzzle

This commit is contained in:
Juan Pablo Vial
2025-06-06 17:11:22 -04:00
parent 2a442417ce
commit d601d7d719
4 changed files with 27 additions and 7 deletions

View File

@ -14,6 +14,7 @@ class Login
public function login(): string
{
$this->logger->info('Logging in');
$url = '/api/login';
try {
$response = $this->client->request('POST', $url, [
@ -39,13 +40,19 @@ class Login
]);
return '';
}
$this->logger->info('Logged in');
$body = $response->getBody()->getContents();
$data = json_decode($body, true);
if (!key_exists('token', $data)) {
$this->logger->error('Token not found');
return '';
}
file_put_contents($this->tokenFilename, $data['token']);
$result = file_put_contents($this->tokenFilename, $data['token']);
if ($result === false) {
$this->logger->error('Failed to save token');
return '';
}
return $data['token'];
}