Commit 4d44f91f authored by Jacob Priddy's avatar Jacob Priddy 👌

Fix some exceptions and error handling

parent 1b802653
......@@ -35,7 +35,7 @@ class LoginController extends Controller
]);
} catch (EntityNotFoundException $e) {
throw ValidationException::withMessages([
'email' => [$e->getMessage()],
'email' => [trans('auth.failed')],
]);
}
......
......@@ -39,7 +39,7 @@ class RequestsController extends Controller
/**
* @param string $requestId
* @param \Source\UseCases\Requests\InteractWithRequest\InteractWithRequestUseCase $interact
* @return \Illuminate\View\View
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Validation\ValidationException
* @throws \Source\Exceptions\EntityNotFoundException
*/
......
......@@ -13,6 +13,7 @@ class APIPresenter extends BasePresenter implements Presenter
public function present(ResponseModel $responseModel): void
{
$this->viewModel['messages'] = $responseModel->getMessages();
$this->viewModel['errors'] = $responseModel->getErrors();
}
/** @inheritDoc */
......
......@@ -31,7 +31,7 @@ class AddDoorToGroup implements AddDoorToGroupUseCase
$this->repository->addDoorToGroup($doorId, $groupId);
$response->addMessage("Attached door $doorId to group $groupId");
} catch (EntityNotFoundException $e) {
$response->addMessage("Failed to attach door $doorId to group $groupId. " . $e->getMessage());
$response->addError("Failed to attach door $doorId to group $groupId. " . $e->getMessage());
}
}
}
......
......@@ -13,6 +13,7 @@ class APIPresenter extends BasePresenter implements Presenter
public function present(ResponseModel $responseModel): void
{
$this->viewModel['messages'] = $responseModel->getMessages();
$this->viewModel['errors'] = $responseModel->getErrors();
}
/** @inheritDoc */
......
......@@ -2,9 +2,11 @@
namespace Source\UseCases\DoorGroup;
use Source\UseCases\HasErrors;
use Source\UseCases\HasMessages;
class ResponseModel
{
use HasMessages;
use HasErrors;
}
......@@ -56,7 +56,7 @@ class AddSchedulesToGroups implements AddSchedulesToGroupsUseCase
$this->groupScheduleRepository->addScheduleToGroup($scheduleId, $groupId);
$response->addMessage("Attached schedule $scheduleId to group $groupId");
} catch (EntityNotFoundException $e) {
$response->addMessage("Failed to attach schedule $scheduleId to group $groupId. " . $e->getMessage());
$response->addError("Failed to attach schedule $scheduleId to group $groupId. " . $e->getMessage());
}
}
}
......
......@@ -11,6 +11,7 @@ class ApiPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel['errors'] = $responseModel->getErrors();
$this->viewModel['messages'] = $responseModel->getMessages();
}
......
......@@ -2,9 +2,11 @@
namespace Source\UseCases\GroupSchedule\AddSchedulesToGroups;
use Source\UseCases\HasErrors;
use Source\UseCases\HasMessages;
class ResponseModel
{
use HasErrors;
use HasMessages;
}
......@@ -11,6 +11,7 @@ class ApiPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel['errors'] = $responseModel->getErrors();
$this->viewModel['messages'] = $responseModel->getMessages();
}
......
......@@ -56,7 +56,7 @@ class RemoveSchedulesFromGroups implements RemoveSchedulesFromGroupsUseCase
$this->groupScheduleRepository->removeSchedulesFromGroups($scheduleId, $groupId);
$response->addMessage("Removed schedule $scheduleId from group $groupId.");
} catch (EntityNotFoundException $e) {
$response->addMessage("Failed to remove schedule $scheduleId from group $groupId. " . $e->getMessage());
$response->addError("Failed to remove schedule $scheduleId from group $groupId. " . $e->getMessage());
}
}
}
......
......@@ -2,9 +2,11 @@
namespace Source\UseCases\GroupSchedule\RemoveSchedulesFromGroups;
use Source\UseCases\HasErrors;
use Source\UseCases\HasMessages;
class ResponseModel
{
use HasErrors;
use HasMessages;
}
......@@ -11,6 +11,7 @@ class APIPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel['errors'] = $responseModel->getErrors();
$this->viewModel['messages'] = $responseModel->getMessages();
}
......
......@@ -43,9 +43,9 @@ class AddUserToGroup implements AddUserToGroupUseCase
$this->repository->addUserToGroup($userId, $groupId);
$response->addMessage("Attached user $userId to group $groupId");
} catch (EntityNotFoundException $e) {
$response->addMessage("Failed to attach user $userId to group $groupId. " . $e->getMessage());
$response->addError("Failed to attach user $userId to group $groupId. " . $e->getMessage());
} catch (AuthorizationException $e) {
$response->addMessage("Failed to attach user $userId to group $groupId. " . $e->getMessage());
$response->addError("Failed to attach user $userId to group $groupId. " . $e->getMessage());
}
}
}
......
......@@ -2,9 +2,11 @@
namespace Source\UseCases\GroupUser\AddUserToGroup;
use Source\UseCases\HasErrors;
use Source\UseCases\HasMessages;
class ResponseModel
{
use HasErrors;
use HasMessages;
}
......@@ -11,6 +11,7 @@ class APIPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel['errors'] = $responseModel->getErrors();
$this->viewModel['messages'] = $responseModel->getMessages();
}
......
......@@ -39,9 +39,9 @@ class RemoveUserFromGroup implements RemoveUserFromGroupUseCase
$this->repository->removeUserFromGroup($userId, $groupId);
$response->addMessage("Removed user $userId from group $groupId");
} catch (EntityNotFoundException $e) {
$response->addMessage("Failed to remove user $userId from group $groupId. " . $e->getMessage());
$response->addError("Failed to remove user $userId from group $groupId. " . $e->getMessage());
} catch (AuthorizationException $e) {
$response->addMessage("Failed to remove user $userId from group $groupId. " . $e->getMessage());
$response->addError("Failed to remove user $userId from group $groupId. " . $e->getMessage());
}
}
}
......
......@@ -2,9 +2,11 @@
namespace Source\UseCases\GroupUser\RemoveUserFromGroup;
use Source\UseCases\HasErrors;
use Source\UseCases\HasMessages;
class ResponseModel
{
use HasErrors;
use HasMessages;
}
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