Last active
March 3, 2021 12:49
-
-
Save emilsoman/5604254 to your computer and use it in GitHub Desktop.
Custom failure app to render a custom json on auth failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomAuthFailure < Devise::FailureApp | |
def respond | |
self.status = 401 | |
self.content_type = 'json' | |
self.response_body = {"errors" => ["Invalid login credentials"]}.to_json | |
end | |
end |
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
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?