class ApplicationController < ActionController::API
  include DeviseTokenAuth::Concerns::SetUserByToken
  include Pundit

  before_action :authenticate_user!

  respond_to :json

  rescue_from ActiveRecord::RecordNotFound, with: :not_found
  rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized

  decent_configuration do
    strategy DecentExposure::StrongParametersStrategy
  end

  private

  def not_found
    respond_with '{"errors":["Not found"]}', status: :not_found, location: nil
  end

  def user_not_authorized
    respond_with '{"errors":["Unauthorized"]}', status: :unauthorized, location: nil
  end
end
