2

This is my code:

application_controller.rb

class ApplicationController < ActionController::API
  include Pundit
end

post_type.rb

Types::QueryType = GraphQL::ObjectType.define do
  name 'Query'

  field :posts, types[Types::PostType] do
    resolve ->(obj, args, ctx) {
      if ctx[:pundit].authorize(Post, :index?)
        Post.all
      else
        nil
      end
    }
  end
end

post_policy.rb

class PostPolicy < ApplicationPolicy
  def index?
    false
  end
end

so now, when request api to graphql, it will result default message:

{
    "status": 500,
    "error": "Internal Server Error",
    "exception": "#<Pundit::NotAuthorizedError: not allowed to index? this Post...",
    "traces": {
      ...
    }
}

I want result custom message, how can i do that? somebody can help me!!!!

Dean
  • 415
  • 1
  • 5
  • 15

0 Answers0