Skip to content

Commit

Permalink
[TASK] add error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Höchtl committed Jan 21, 2019
1 parent 7815cd6 commit 8adffff
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Classes/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Exception extends FlowException
{
const NO_FOM_SELECTED_CODE = 1536740278;
const NO_FOM_SELECTED_MESSAGE = 'No form selected';
const FORM_UNAVAILABLE_CODE = 1548082903;
const FORM_UNAVAILABLE_MESSAGE = 'Form unavailable';

/**
* @return Exception
Expand All @@ -25,4 +27,9 @@ public static function noFormSelected(): Exception
{
return new self(self::NO_FOM_SELECTED_MESSAGE, self::NO_FOM_SELECTED_CODE);
}

public static function formUnavailable(): Exception
{
return new self(self::FORM_UNAVAILABLE_MESSAGE, self::FORM_UNAVAILABLE_CODE);
}
}
1 change: 1 addition & 0 deletions Classes/FusionObjects/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected function handle($fusionPath, \Exception $exception, $referenceCode):st
if (Exception::NO_FOM_SELECTED_CODE === $exception->getCode()) {
return $this->runtime->render($fusionPath . '/noForm');
}

return (string)$exception;
}
}
2 changes: 1 addition & 1 deletion Classes/FusionObjects/FormRuntimeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function evaluate(): string
$this->runtime
);
if (empty($formDefinition)) {
throw new Exception('Please select a form');
throw Exception::formUnavailable();
}

$request = $this->getRuntime()->getControllerContext()->getRequest();
Expand Down
9 changes: 9 additions & 0 deletions Classes/Service/HubspotFormService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Neos\Cache\Frontend\VariableFrontend;
use Neos\Flow\Annotations as Flow;
use Psr\Log\LoggerInterface;
use SevenShores\Hubspot\Exceptions\BadRequest;
use SevenShores\Hubspot\Factory;
use SevenShores\Hubspot\Resources\Forms;
Expand Down Expand Up @@ -44,6 +45,12 @@ class HubspotFormService
*/
protected $settings = [];

/**
* @Flow\Inject
* @var \Neos\Flow\Log\SystemLoggerInterface
*/
protected $systemLogger;

/**
* HubspotFormService constructor.
*/
Expand Down Expand Up @@ -124,9 +131,11 @@ public function getFormByIdentifier(string $formIdentifier = null): array
try {
$response = $this->forms->getById($formIdentifier);
} catch (BadRequest $exception) {
$this->systemLogger->logException($exception);
return [];
}
if (200 !== $response->getStatusCode()) {
$this->systemLogger->log('Hubspot API returned non 200 code', LOG_ERR, ['responseCode' => $response->getStatusCode()]);
return [];
}

Expand Down
9 changes: 9 additions & 0 deletions Resources/Private/Fusion/Content/Form.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ prototype(Onedrop.Form.Hubspot:FormRuntimeFactory) {
content = 'Please select a hubspot form in the element inspector'
@process.contentElementWrapping = Neos.Neos:ContentElementWrapping
}

formUnavailable = Neos.Fusion:Tag {
tagName = 'div'
attributes {
class = 'onedrophubspot_noform'
}
content = 'The forms are temporarily not available'
@process.contentElementWrapping = Neos.Neos:ContentElementWrapping
}
}

prototype(Onedrop.Form.Hubspot:Content.Form) < prototype(Neos.Neos:ContentComponent) {
Expand Down

0 comments on commit 8adffff

Please sign in to comment.