Skip to content

Instantly share code, notes, and snippets.

@bitwerx-tyler
Created February 20, 2020 21:28
Show Gist options
  • Save bitwerx-tyler/73a8802a9a7790ce4d79cf2eed80453d to your computer and use it in GitHub Desktop.
Save bitwerx-tyler/73a8802a9a7790ce4d79cf2eed80453d to your computer and use it in GitHub Desktop.
Custom failure app for devise-jwt to respond in JSON format
# 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