Skip to content

Commit

Permalink
Allow defining a custom raise_user_error_list method
Browse files Browse the repository at this point in the history
By changing the arguments raise_user_error_list receives,
we allow users to customize the errors they raise
by simply passing the failed resource to the method
  • Loading branch information
mcelicalderon committed Oct 29, 2023
1 parent b1435ba commit 03fc56e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/graphql_devise/concerns/controller_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def raise_user_error(message)
raise UserError, message
end

def raise_user_error_list(message, errors:)
raise DetailedUserError.new(message, errors: errors)
def raise_user_error_list(message, resource:)
raise DetailedUserError.new(message, errors: resource.errors.full_messages)
end

def remove_resource
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql_devise/mutations/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def resolve(confirm_url: nil, **attrs)
resource.try(:clean_up_passwords)
raise_user_error_list(
I18n.t('graphql_devise.registration_failed'),
errors: resource.errors.full_messages
resource: resource
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def resolve(email:, redirect_url:)
if resource.errors.empty?
{ message: I18n.t('graphql_devise.passwords.send_instructions') }
else
raise_user_error_list(I18n.t('graphql_devise.invalid_resource'), errors: resource.errors.full_messages)
raise_user_error_list(I18n.t('graphql_devise.invalid_resource'), resource: resource)
end
else
raise_user_error(I18n.t('graphql_devise.user_not_found'))
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql_devise/mutations/update_password_with_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def resolve(reset_password_token:, **attrs)
else
raise_user_error_list(
I18n.t('graphql_devise.passwords.update_password_error'),
errors: resource.errors.full_messages
resource: resource
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def resolve(**attrs)
else
raise_user_error_list(
'Custom registration failed',
errors: user.errors.full_messages
resource: user
)
end
end
Expand Down

0 comments on commit 03fc56e

Please sign in to comment.