Sha256: 09540e9ce7a7dc48822bbb132853cbea0e9be0faf3daf26f443ca610fb4bf01d

Contents?: true

Size: 904 Bytes

Versions: 2

Compression:

Stored size: 904 Bytes

Contents

module Federails
  class ServerController < ::ActionController::Base # rubocop:disable Rails/ApplicationController
    include Pundit::Authorization

    after_action :verify_authorized

    protect_from_forgery with: :null_session
    helper Federails::ServerHelper

    rescue_from ActiveRecord::RecordNotFound, with: :error_not_found

    private

    def error_fallback(exception, fallback_message, status)
      message = exception&.message || fallback_message
      respond_to do |format|
        format.jrd { head status }
        format.xrd { head status }
        format.activitypub { head status }
        format.nodeinfo { head status }
        format.json { render json: { error: message }, status: status }
        format.html { raise exception }
      end
    end

    def error_not_found(exception = nil)
      error_fallback(exception, 'Resource not found', :not_found)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
federails-0.4.0 app/controllers/federails/server_controller.rb
federails-0.3.0 app/controllers/federails/server_controller.rb