Exception: GraphQL::UnauthorizedError

Inherits:
Error
  • Object
show all
Defined in:
lib/graphql/unauthorized_error.rb

Overview

When an authorized? hook returns false, this error is used to communicate the failure. It's passed to Schema.unauthorized_object.

Alternatively, custom code in authorized? may raise this error. It will be routed the same way.

Direct Known Subclasses

UnauthorizedFieldError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, object: nil, type: nil, context: nil) ⇒ UnauthorizedError


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/graphql/unauthorized_error.rb', line 17

def initialize(message = nil, object: nil, type: nil, context: nil)
  if message.nil? && object.nil? && type.nil?
    raise ArgumentError, "#{self.class.name} requires either a message or keywords"
  end

  @object = object
  @type = type
  @context = context
  message ||= "An instance of #{object.class} failed #{type.name}'s authorization check"
  super(message)
end

Instance Attribute Details

#contextGraphQL::Query::Context (readonly)


15
16
17
# File 'lib/graphql/unauthorized_error.rb', line 15

def context
  @context
end

#objectObject (readonly)


9
10
11
# File 'lib/graphql/unauthorized_error.rb', line 9

def object
  @object
end

#typeClass (readonly)


12
13
14
# File 'lib/graphql/unauthorized_error.rb', line 12

def type
  @type
end