AlchemyCMS/alchemy_cms

View on GitHub
app/controllers/alchemy/api/base_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module Alchemy
  class Api::BaseController < Alchemy::BaseController
    layout false

    rescue_from CanCan::AccessDenied, with: :render_not_authorized
    rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
    rescue_from ActionController::RoutingError, with: :render_not_found

    private

    def render_not_authorized
      render json: {error: "Not authorized"}, status: 403
    end

    def render_not_found
      render json: {error: "Record not found"}, status: 404
    end
  end
end