Skip to content

Commit

Permalink
fix: standarize errors in events context
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsp45 committed Oct 11, 2023
1 parent 00ba0ca commit 40b20cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/bokken/events.ex
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ defmodule Bokken.Events do
if DateTime.compare(event.enrollments_open, cur_time) == :lt and
DateTime.compare(event.enrollments_close, cur_time) == :gt do
if is_ninja_enrolled?(ninja_id, event.id) do
{:error, :ninja_already_enrolled}
{:error, :already_enrolled}
else
insert_enrollment(role, attrs)
end
Expand Down Expand Up @@ -713,7 +713,7 @@ defmodule Bokken.Events do
if DateTime.compare(event.start_time, cur_time) == :gt do
Repo.delete(enrollment)
else
{:error, "Cannot delete enrollment of past session"}
{:error, :not_authorized}
end
end

Expand Down Expand Up @@ -851,14 +851,14 @@ defmodule Bokken.Events do
if DateTime.compare(event.enrollments_open, current_time) == :lt and
DateTime.compare(event.enrollments_close, current_time) == :gt do
if mentor_availability_exists?(mentor_id, event.id) do
{:error, "Mentor has already stated availability for this event"}
{:error, :already_enrolled}
else
%Availability{}
|> Availability.changeset(attrs)
|> Repo.insert()
end
else
{:error, "Availability cannot be created when event enrollments are closed"}
{:error, :enrollments_closed}
end
end

Expand Down
6 changes: 2 additions & 4 deletions lib/bokken/guards.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ defmodule Bokken.Guards do
"""
defguard is_404(reason) when reason in [:not_found, :not_registered, :invalid_credentials]
defguard is_401(reason) when reason in [:token_expired]
defguard is_401(reason) when reason in [:not_authorized, :token_expired]

defguard is_403(reason)
when reason in [
:not_authorized,
:not_allowed,
:ninja_already_enrolled,
:already_enrolled,
:enrollments_closed
]
end

0 comments on commit 40b20cb

Please sign in to comment.