Catch OpenSSL error.

This commit is contained in:
James Cole
2018-05-23 14:08:37 +02:00
parent 2b2f37a8c9
commit 82538ba4fc
3 changed files with 44 additions and 6 deletions

View File

@@ -26,6 +26,7 @@ use bunq\Context\ApiContext;
use bunq\Exception\BadRequestException;
use bunq\Exception\BunqException;
use bunq\Util\BunqEnumApiEnvironmentType;
use Exception;
use FireflyIII\Services\IP\IPRetrievalInterface;
use FireflyIII\User;
use Illuminate\Support\MessageBag;
@@ -122,9 +123,16 @@ class BunqPrerequisites implements PrerequisitesInterface
$deviceDescription,
$permittedIps
);
} catch (BadRequestException $e) {
} catch (BadRequestException|BunqException|Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$message = $e->getMessage();
if (stripos($message, 'Generating a new private key failed')) {
$message = 'Could not generate key-material. Please make sure OpenSSL is installed and configured: http://bit.ly/FF3-openSSL';
}
$messages = new MessageBag();
$messages->add('bunq_error', $e->getMessage());
$messages->add('bunq_error', $message);
return $messages;
}

View File

@@ -25,9 +25,12 @@ namespace FireflyIII\Support\Import\Routine\Bunq;
use bunq\Context\ApiContext;
use bunq\Context\BunqContext;
use bunq\Exception\BadRequestException;
use bunq\Exception\BunqException;
use bunq\Model\Generated\Endpoint\Payment;
use bunq\Model\Generated\Object\LabelMonetaryAccount;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\Account as LocalAccount;
@@ -242,7 +245,18 @@ class StageImportDataHandler
$preference = app('preferences')->getForUser($this->importJob->user, 'bunq_api_context', null);
if (null !== $preference && '' !== (string)$preference->data) {
// restore API context
try {
$apiContext = ApiContext::fromJson($preference->data);
} catch (BadRequestException|BunqException|Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$message = $e->getMessage();
if (stripos($message, 'Generating a new private key failed')) {
$message = 'Could not generate key-material. Please make sure OpenSSL is installed and configured: http://bit.ly/FF3-openSSL';
}
throw new FireflyException($message);
}
BunqContext::loadApiContext($apiContext);
return;

View File

@@ -25,14 +25,18 @@ namespace FireflyIII\Support\Import\Routine\Bunq;
use bunq\Context\ApiContext;
use bunq\Context\BunqContext;
use bunq\Exception\BadRequestException;
use bunq\Exception\BunqException;
use bunq\Model\Generated\Endpoint\MonetaryAccount;
use bunq\Model\Generated\Endpoint\MonetaryAccountBank;
use bunq\Model\Generated\Object\Pointer;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use Log;
/**
* Class StageNewHandler
*/
@@ -52,8 +56,19 @@ class StageNewHandler
$preference = app('preferences')->getForUser($this->importJob->user, 'bunq_api_context', null);
if (null !== $preference && '' !== (string)$preference->data) {
// restore API context
try {
$apiContext = ApiContext::fromJson($preference->data);
BunqContext::loadApiContext($apiContext);
} catch (BadRequestException|BunqException|Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$message = $e->getMessage();
if (stripos($message, 'Generating a new private key failed')) {
$message = 'Could not generate key-material. Please make sure OpenSSL is installed and configured: http://bit.ly/FF3-openSSL';
}
throw new FireflyException($message);
}
// list bunq accounts:
$accounts = $this->listAccounts();
@@ -62,6 +77,7 @@ class StageNewHandler
$config = $this->repository->getConfiguration($this->importJob);
$config['accounts'] = $accounts;
$this->repository->setConfiguration($this->importJob, $config);
return;
}
throw new FireflyException('The bunq API context is unexpectedly empty.');