-
-
Save ty-porter/3c5613b34f85ec48b1b61f8fa79677b1 to your computer and use it in GitHub Desktop.
Custom failure app for devise-jwt to respond in JSON format
This file contains 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
# frozen_string_literal: true | |
module Devise | |
# Failure application that will be called every time :warden is thrown from | |
# any strategy or hook. This application overrides the default Devise | |
# failure application in order to render messages as JSON. | |
class ApiFailureApp < Devise::FailureApp | |
def respond | |
json_api_error_response | |
end | |
def json_api_error_response | |
self.status = 401 | |
self.content_type = 'application/json' | |
self.response_body = { errors: [{ message: i18n_message }] }.to_json | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment