How to get underlying error?
kunicmarko20 opened this issue · comments
Marko Kunic commented
write
method is returning false and I have no idea why, is there a way to get the error from phplibsec?
Slava Basko commented
Did you find a way to get errors?
Marko Kunic commented
hey @slava-basko I ended up extending the SftpAdapter
and overwriting write
method:
final class SftpAdapter extends \League\Flysystem\Sftp\SftpAdapter
{
private LoggerInterface $logger;
/**
* @param array<string, mixed> $config
*/
public function __construct(array $config, LoggerInterface $logger)
{
parent::__construct($config);
$this->logger = $logger;
}
/**
* @param string $path
* @param string $contents
*
* @return array<string, mixed>|false
*/
public function write($path, $contents, Config $config)
{
$response = parent::write($path, $contents, $config);
if ($response === false) {
$this->logger->error($this->connection->getLastSFTPError());
}
return $response;
}
}
Slava Basko commented
Right now i'm dealing with legacy which don't have PSR logger. But your option makes sense for me. Thanks!