Skip to content

Commit

Permalink
Set GraphQlInputException when not formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
sedonik committed Aug 5, 2019
1 parent f94b4a8 commit 439830d
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Catalog\Model\Product\Option\Type\Date as ProductDateOptionType;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Stdlib\DateTime;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;

/**
* @inheritdoc
Expand Down Expand Up @@ -43,6 +44,13 @@ private function formatValues($values)
if (isset($values[$this->getOption()->getId()])) {
$value = $values[$this->getOption()->getId()];
$dateTime = \DateTime::createFromFormat(DateTime::DATETIME_PHP_FORMAT, $value);

if (!$dateTime) {
throw new GraphQlInputException(
__('Invalid format provided. Please use \'Y-m-d H:i:s\' format.')
);
}

$values[$this->getOption()->getId()] = [
'date' => $value,
'year' => $dateTime->format('Y'),
Expand Down

0 comments on commit 439830d

Please sign in to comment.