Unify automation endpoint 404 exceptions
[MAILPOET-5436]
This commit is contained in:
committed by
Aschepikov
parent
8376494d6f
commit
ac751871f9
@@ -68,6 +68,13 @@ class Exceptions {
|
|||||||
->withMessage(sprintf(__("Automation with ID '%d' not found.", 'mailpoet'), $id));
|
->withMessage(sprintf(__("Automation with ID '%d' not found.", 'mailpoet'), $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function automationNotFoundInTimeSpan(int $id): NotFoundException {
|
||||||
|
return NotFoundException::create()
|
||||||
|
->withErrorCode(self::AUTOMATION_NOT_FOUND)
|
||||||
|
// translators: %d is the ID of the automation.
|
||||||
|
->withMessage(sprintf(__("Automation with ID '%d' not found in selected time span.", 'mailpoet'), $id));
|
||||||
|
}
|
||||||
|
|
||||||
public static function automationVersionNotFound(int $automation, int $version): NotFoundException {
|
public static function automationVersionNotFound(int $automation, int $version): NotFoundException {
|
||||||
return NotFoundException::create()
|
return NotFoundException::create()
|
||||||
->withErrorCode(self::AUTOMATION_VERSION_NOT_FOUND)
|
->withErrorCode(self::AUTOMATION_VERSION_NOT_FOUND)
|
||||||
|
@@ -6,7 +6,7 @@ use MailPoet\API\REST\Request;
|
|||||||
use MailPoet\API\REST\Response;
|
use MailPoet\API\REST\Response;
|
||||||
use MailPoet\Automation\Engine\API\Endpoint;
|
use MailPoet\Automation\Engine\API\Endpoint;
|
||||||
use MailPoet\Automation\Engine\Data\Automation;
|
use MailPoet\Automation\Engine\Data\Automation;
|
||||||
use MailPoet\Automation\Engine\Exceptions\NotFoundException;
|
use MailPoet\Automation\Engine\Exceptions;
|
||||||
use MailPoet\Automation\Engine\Mappers\AutomationMapper;
|
use MailPoet\Automation\Engine\Mappers\AutomationMapper;
|
||||||
use MailPoet\Automation\Engine\Storage\AutomationStatisticsStorage;
|
use MailPoet\Automation\Engine\Storage\AutomationStatisticsStorage;
|
||||||
use MailPoet\Automation\Engine\Storage\AutomationStorage;
|
use MailPoet\Automation\Engine\Storage\AutomationStorage;
|
||||||
@@ -47,14 +47,15 @@ class AutomationFlowEndpoint extends Endpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Request $request): Response {
|
public function handle(Request $request): Response {
|
||||||
$automation = $this->automationStorage->getAutomation(absint($request->getParam('id')));
|
$id = absint($request->getParam('id'));
|
||||||
|
$automation = $this->automationStorage->getAutomation($id);
|
||||||
if (!$automation) {
|
if (!$automation) {
|
||||||
throw new NotFoundException(__('Automation not found', 'mailpoet'));
|
throw Exceptions::automationNotFound($id);
|
||||||
}
|
}
|
||||||
$query = Query::fromRequest($request);
|
$query = Query::fromRequest($request);
|
||||||
$automations = $this->automationTimeSpanController->getAutomationsInTimespan($automation, $query->getAfter(), $query->getBefore());
|
$automations = $this->automationTimeSpanController->getAutomationsInTimespan($automation, $query->getAfter(), $query->getBefore());
|
||||||
if (!count($automations)) {
|
if (!count($automations)) {
|
||||||
throw new NotFoundException(__('The automation did not exist in the selected time span', 'mailpoet'));
|
throw Exceptions::automationNotFoundInTimeSpan($id);
|
||||||
}
|
}
|
||||||
$automation = current($automations);
|
$automation = current($automations);
|
||||||
$shortStatistics = $this->automationStatisticsStorage->getAutomationStats(
|
$shortStatistics = $this->automationStatisticsStorage->getAutomationStats(
|
||||||
|
@@ -5,7 +5,7 @@ namespace MailPoet\Automation\Integrations\MailPoet\Analytics\Endpoints;
|
|||||||
use MailPoet\API\REST\Request;
|
use MailPoet\API\REST\Request;
|
||||||
use MailPoet\API\REST\Response;
|
use MailPoet\API\REST\Response;
|
||||||
use MailPoet\Automation\Engine\API\Endpoint;
|
use MailPoet\Automation\Engine\API\Endpoint;
|
||||||
use MailPoet\Automation\Engine\Exceptions\NotFoundException;
|
use MailPoet\Automation\Engine\Exceptions;
|
||||||
use MailPoet\Automation\Engine\Storage\AutomationStorage;
|
use MailPoet\Automation\Engine\Storage\AutomationStorage;
|
||||||
use MailPoet\Automation\Integrations\MailPoet\Analytics\Controller\OverviewStatisticsController;
|
use MailPoet\Automation\Integrations\MailPoet\Analytics\Controller\OverviewStatisticsController;
|
||||||
use MailPoet\Automation\Integrations\MailPoet\Analytics\Entities\QueryWithCompare;
|
use MailPoet\Automation\Integrations\MailPoet\Analytics\Entities\QueryWithCompare;
|
||||||
@@ -28,9 +28,10 @@ class OverviewEndpoint extends Endpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Request $request): Response {
|
public function handle(Request $request): Response {
|
||||||
$automation = $this->automationStorage->getAutomation((int)$request->getParam('id'));
|
$id = absint($request->getParam('id'));
|
||||||
|
$automation = $this->automationStorage->getAutomation($id);
|
||||||
if (!$automation) {
|
if (!$automation) {
|
||||||
throw new NotFoundException(__('Automation not found', 'mailpoet'));
|
throw Exceptions::automationNotFound($id);
|
||||||
}
|
}
|
||||||
$query = QueryWithCompare::fromRequest($request);
|
$query = QueryWithCompare::fromRequest($request);
|
||||||
|
|
||||||
|
@@ -5,10 +5,6 @@ parameters:
|
|||||||
message: "#^Cannot cast mixed to string\\.$#"
|
message: "#^Cannot cast mixed to string\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
path: ../../lib/Automation/Engine/Endpoints/Automations/AutomationsCreateFromTemplateEndpoint.php
|
path: ../../lib/Automation/Engine/Endpoints/Automations/AutomationsCreateFromTemplateEndpoint.php
|
||||||
-
|
|
||||||
message: "#^Cannot cast mixed to int\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: ../../lib/Automation/Integrations/MailPoet/Analytics/Endpoints/OverviewEndpoint.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Cannot access property \\$permissions on mixed\\.$#"
|
message: "#^Cannot access property \\$permissions on mixed\\.$#"
|
||||||
|
@@ -5,10 +5,6 @@ parameters:
|
|||||||
message: "#^Cannot cast mixed to string\\.$#"
|
message: "#^Cannot cast mixed to string\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
path: ../../lib/Automation/Engine/Endpoints/Automations/AutomationsCreateFromTemplateEndpoint.php
|
path: ../../lib/Automation/Engine/Endpoints/Automations/AutomationsCreateFromTemplateEndpoint.php
|
||||||
-
|
|
||||||
message: "#^Cannot cast mixed to int\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: ../../lib/Automation/Integrations/MailPoet/Analytics/Endpoints/OverviewEndpoint.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Cannot access property \\$permissions on mixed\\.$#"
|
message: "#^Cannot access property \\$permissions on mixed\\.$#"
|
||||||
|
Reference in New Issue
Block a user