Skip to content

Instantly share code, notes, and snippets.

@emilsoman
Last active March 3, 2021 12:49
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save emilsoman/5604254 to your computer and use it in GitHub Desktop.
Save emilsoman/5604254 to your computer and use it in GitHub Desktop.
Custom failure app to render a custom json on auth failure
class CustomAuthFailure < Devise::FailureApp
def respond
self.status = 401
self.content_type = 'json'
self.response_body = {"errors" => ["Invalid login credentials"]}.to_json
end
end
@brunobortolotti
Copy link

I've used this implementation and it works almost every time. The problem appears when I try to register a user with an existing email address. Rails will skip right to a PG exception. Any thoughts?

You're getting the PG exception probably because you're missing the validations on the User model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment