Commit 11e61c03 authored by Roman Ondráček's avatar Roman Ondráček

IQRF net: add error messages for incorrect DPA sections (fix #221)

Signed-off-by: Roman Ondráček's avatarRoman Ondráček <ondracek.roman@centrum.cz>
parent e8aceedd
Pipeline #2410 passed with stages
in 19 minutes and 5 seconds
......@@ -25,6 +25,12 @@ use App\CoreModule\Exceptions\NonExistingJsonSchemaException;
use App\CoreModule\Forms\FormFactory;
use App\IqrfNetModule\Exceptions\DpaErrorException;
use App\IqrfNetModule\Exceptions\EmptyResponseException;
use App\IqrfNetModule\Exceptions\IncorrectDataException;
use App\IqrfNetModule\Exceptions\IncorrectDataLengthException;
use App\IqrfNetModule\Exceptions\IncorrectHwpidUsedException;
use App\IqrfNetModule\Exceptions\IncorrectNadrException;
use App\IqrfNetModule\Exceptions\IncorrectPcmdException;
use App\IqrfNetModule\Exceptions\IncorrectPnumException;
use App\IqrfNetModule\Models\ApiSchemaManager;
use App\IqrfNetModule\Models\WebSocketClient;
use App\IqrfNetModule\Presenters\SendJsonPresenter;
......@@ -146,11 +152,23 @@ class SendJsonFormFactory {
$rsp = new ApiResponse();
$rsp->set(Json::encode($response['response']));
$rsp->checkStatus();
$this->presenter->flashSuccess('iqrfnet.send-json.messages.success');
$this->presenter->flashSuccess(self::PREFIX . 'messages.success');
} catch (IncorrectNadrException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectNadr');
} catch (IncorrectPnumException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectPnum');
} catch (IncorrectPcmdException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectPcmd');
} catch (IncorrectHwpidUsedException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectHwpid');
} catch (IncorrectDataException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectData');
} catch (IncorrectDataLengthException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectDataLength');
} catch (DpaErrorException | EmptyResponseException $e) {
$this->presenter->flashError('iqrfnet.webSocketClient.messages.emptyResponse');
} catch (JsonException $e) {
$this->presenter->flashError('iqrfnet.send-json.messages.failure');
$this->presenter->flashError(self::PREFIX . 'messages.failure');
}
}
......
......@@ -23,6 +23,12 @@ namespace App\IqrfNetModule\Forms;
use App\CoreModule\Forms\FormFactory;
use App\IqrfNetModule\Exceptions\DpaErrorException;
use App\IqrfNetModule\Exceptions\EmptyResponseException;
use App\IqrfNetModule\Exceptions\IncorrectDataException;
use App\IqrfNetModule\Exceptions\IncorrectDataLengthException;
use App\IqrfNetModule\Exceptions\IncorrectHwpidUsedException;
use App\IqrfNetModule\Exceptions\IncorrectNadrException;
use App\IqrfNetModule\Exceptions\IncorrectPcmdException;
use App\IqrfNetModule\Exceptions\IncorrectPnumException;
use App\IqrfNetModule\Models\DpaRawManager;
use App\IqrfNetModule\Presenters\SendRawPresenter;
use Nette\Application\UI\Form;
......@@ -51,6 +57,11 @@ class SendRawFormFactory {
*/
private $presenter;
/**
* Translation prefix
*/
private const PREFIX = 'iqrfnet.send-packet.';
/**
* Constructor
* @param FormFactory $factory Generic form factory
......@@ -101,7 +112,7 @@ class SendRawFormFactory {
$packet = $values->packet;
$timeout = ($values->timeoutEnabled === true) ? $values->timeout : null;
if (!$this->manager->validatePacket($packet)) {
$this->presenter->flashError('iqrfnet.send-packet.messages.invalidPacket');
$this->presenter->flashError(self::PREFIX . 'messages.invalidPacket');
return;
}
if ($values->overwriteAddress === true) {
......@@ -111,7 +122,19 @@ class SendRawFormFactory {
try {
$response = $this->manager->send($packet, $timeout);
$this->presenter->handleShowResponse($response);
$this->presenter->flashSuccess('iqrfnet.send-packet.messages.success');
$this->presenter->flashSuccess(self::PREFIX . 'messages.success');
} catch (IncorrectNadrException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectNadr');
} catch (IncorrectPnumException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectPnum');
} catch (IncorrectPcmdException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectPcmd');
} catch (IncorrectHwpidUsedException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectHwpid');
} catch (IncorrectDataException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectData');
} catch (IncorrectDataLengthException $e) {
$this->presenter->flashError(self::PREFIX . 'messages.incorrectDataLength');
} catch (EmptyResponseException | DpaErrorException $e) {
$this->presenter->flashError('iqrfnet.webSocketClient.messages.emptyResponse');
}
......
......@@ -208,6 +208,12 @@ send-json:
missingSchema: Corresponding JSON schema for this request not found.
failure: An error occurred while proccesing JSON request.
success: JSON request has been sent successfully.
incorrectNadr: Sent JSON request contains incorrect NADR.
incorrectPcmd: Sent JSON request contains incorrect PCMD.
incorrectPnum: Sent JSON request contains incorrect PNUM.
incorrectHwpid: Sent JSON request contains incorrect HWPID has been used.
incorrectData: Sent JSON request contains incorrect data.
incorrectDataLength: Sent JSON request contains incorrect data length.
send: Send
response: Response
request: Request
......@@ -225,6 +231,12 @@ send-packet:
invalidPacket: Invalid DPA packet.
packet: Please enter DPA packet.
success: DPA packet has been sent successfully.
incorrectNadr: Sent DPA packet contains incorrect NADR.
incorrectPcmd: Sent DPA packet contains incorrect PCMD.
incorrectPnum: Sent DPA packet contains incorrect PNUM.
incorrectHwpid: Sent DPA packet contains incorrect HWPID has been used.
incorrectData: Sent DPA packet contains incorrect data.
incorrectDataLength: Sent DPA packet contains incorrect data length.
send: Send
parsed-response: Parsed response
response: Response
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment