Expand code for Spectre login.

This commit is contained in:
James Cole
2018-01-02 15:17:31 +01:00
parent d49aecdf49
commit 3f786856f3
12 changed files with 667 additions and 14 deletions

View File

@@ -23,6 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Services\Spectre\Request;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Services\Spectre\Exception\DuplicatedCustomerException;
use FireflyIII\Services\Spectre\Exception\SpectreException;
use FireflyIII\User;
use Log;
use Requests;
@@ -179,6 +181,7 @@ abstract class SpectreRequest
* @return array
*
* @throws FireflyException
* @throws SpectreException
*/
protected function sendSignedSpectreGet(string $uri, array $data): array
{
@@ -222,6 +225,7 @@ abstract class SpectreRequest
* @return array
*
* @throws FireflyException
* @throws SpectreException
*/
protected function sendSignedSpectrePost(string $uri, array $data): array
{
@@ -255,15 +259,21 @@ abstract class SpectreRequest
* @param Requests_Response $response
*
* @throws FireflyException
* @throws SpectreException
*/
private function detectError(Requests_Response $response): void
{
$body = $response->body;
$array = json_decode($body, true);
if (isset($array['error_class'])) {
$message = $array['error_message'] ?? '(no message)';
$message = $array['error_message'] ?? '(no message)';
$errorClass = $array['error_class'];
$class = sprintf('\\FireflyIII\\Services\\Spectre\Exception\\%sException', $errorClass);
if (class_exists($class)) {
throw new $class($message);
}
throw new FireflyException(sprintf('Error of class %s: %s', $array['error_class'], $message));
throw new FireflyException(sprintf('Error of class %s: %s', $errorClass, $message));
}
$statusCode = intval($response->status_code);