diff --git a/app/Bus/Handlers/Commands/Schedule/CreateScheduleCommandHandler.php b/app/Bus/Handlers/Commands/Schedule/CreateScheduleCommandHandler.php index 92ec22cc..23de4933 100644 --- a/app/Bus/Handlers/Commands/Schedule/CreateScheduleCommandHandler.php +++ b/app/Bus/Handlers/Commands/Schedule/CreateScheduleCommandHandler.php @@ -11,11 +11,14 @@ namespace CachetHQ\Cachet\Bus\Handlers\Commands\Schedule; +use AltThree\Validator\ValidationException; use CachetHQ\Cachet\Bus\Commands\Schedule\CreateScheduleCommand; use CachetHQ\Cachet\Bus\Events\Schedule\ScheduleWasCreatedEvent; use CachetHQ\Cachet\Models\Schedule; use CachetHQ\Cachet\Services\Dates\DateFactory; use Illuminate\Contracts\Auth\Guard; +use Illuminate\Support\MessageBag; +use InvalidArgumentException; /** * This is the create schedule command handler. @@ -61,9 +64,13 @@ class CreateScheduleCommandHandler */ public function handle(CreateScheduleCommand $command) { - $schedule = Schedule::create($this->filter($command)); + try { + $schedule = Schedule::create($this->filter($command)); - event(new ScheduleWasCreatedEvent($this->auth->user(), $schedule)); + event(new ScheduleWasCreatedEvent($this->auth->user(), $schedule)); + } catch (InvalidArgumentException $e) { + throw new ValidationException(new MessageBag([$e->getMessage()])); + } return $schedule; } diff --git a/app/Http/Controllers/Dashboard/ScheduleController.php b/app/Http/Controllers/Dashboard/ScheduleController.php index f9dfd23b..6d9bcfaa 100644 --- a/app/Http/Controllers/Dashboard/ScheduleController.php +++ b/app/Http/Controllers/Dashboard/ScheduleController.php @@ -92,7 +92,7 @@ class ScheduleController extends Controller } catch (ValidationException $e) { return cachet_redirect('dashboard.schedule.create') ->withInput(Binput::all()) - ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.add.failure'))) + ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure'))) ->withErrors($e->getMessageBag()); }