hensei-api/app/errors/crew_errors.rb
Justin Edmund b75a905e2e add crew invitations system
- create crew_invitations table with status enum
- add CrewInvitation model with accept/reject flow
- add CrewInvitationsController for send/accept/reject
- add invitation error classes
- add invitation routes nested under crews
- add pending invitations endpoint for current user
- 38 passing specs for model and controller
2025-12-03 23:06:07 -08:00

175 lines
2.6 KiB
Ruby

# frozen_string_literal: true
module CrewErrors
# Base class for all crew-related errors
class CrewError < StandardError
def http_status
:unprocessable_entity
end
def code
self.class.name.demodulize.underscore
end
def to_hash
{
message: message,
code: code
}
end
end
class AlreadyInCrewError < CrewError
def http_status
:unprocessable_entity
end
def code
'already_in_crew'
end
def message
'You are already in a crew'
end
end
class CaptainCannotLeaveError < CrewError
def http_status
:unprocessable_entity
end
def code
'captain_cannot_leave'
end
def message
'Captain must transfer ownership before leaving'
end
end
class CannotRemoveCaptainError < CrewError
def http_status
:unprocessable_entity
end
def code
'cannot_remove_captain'
end
def message
'Cannot remove the captain from the crew'
end
end
class ViceCaptainLimitError < CrewError
def http_status
:unprocessable_entity
end
def code
'vice_captain_limit'
end
def message
'Crew can only have up to 3 vice captains'
end
end
class NotInCrewError < CrewError
def http_status
:unprocessable_entity
end
def code
'not_in_crew'
end
def message
'You are not in a crew'
end
end
class MemberNotFoundError < CrewError
def http_status
:not_found
end
def code
'member_not_found'
end
def message
'Member not found in this crew'
end
end
class CannotDemoteCaptainError < CrewError
def http_status
:unprocessable_entity
end
def code
'cannot_demote_captain'
end
def message
'Cannot demote the captain'
end
end
class InvitationExpiredError < CrewError
def http_status
:gone
end
def code
'invitation_expired'
end
def message
'This invitation has expired'
end
end
class InvitationNotFoundError < CrewError
def http_status
:not_found
end
def code
'invitation_not_found'
end
def message
'Invitation not found'
end
end
class CannotInviteSelfError < CrewError
def http_status
:unprocessable_entity
end
def code
'cannot_invite_self'
end
def message
'You cannot invite yourself'
end
end
class UserAlreadyInvitedError < CrewError
def http_status
:conflict
end
def code
'user_already_invited'
end
def message
'User already has a pending invitation'
end
end
end