Class: GraphitiGql::ExceptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti_gql/exception_handler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(err, obj, args, ctx, field) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.



19
20
21
22
23
24
25
26
# File 'lib/graphiti_gql/exception_handler.rb', line 19

def initialize(err, obj, args, ctx, field)
  @error = err
  @obj = obj
  @args = args
  @context = ctx
  @field = field
  @config = get_config(err)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/graphiti_gql/exception_handler.rb', line 3

def context
  @context
end

#errorObject (readonly)

Returns the value of attribute error.



3
4
5
# File 'lib/graphiti_gql/exception_handler.rb', line 3

def error
  @error
end

#fieldObject (readonly)

Returns the value of attribute field.



3
4
5
# File 'lib/graphiti_gql/exception_handler.rb', line 3

def field
  @field
end

Class Method Details

.register_exception(err, opts) ⇒ Object



10
11
12
# File 'lib/graphiti_gql/exception_handler.rb', line 10

def self.register_exception(err, opts)
  registry[err] = opts
end

Instance Method Details

#handleObject

Raises:

  • (GraphQL::ExecutionError)


36
37
38
39
40
41
42
43
# File 'lib/graphiti_gql/exception_handler.rb', line 36

def handle
  notify if @config[:notify] != false
  log if @config[:log] != false

  message = @config[:message] ? err.message : default_message
  code = @config[:code] || default_code
  raise GraphQL::ExecutionError.new(message, extensions: { code: code })
end

#logObject



32
33
34
# File 'lib/graphiti_gql/exception_handler.rb', line 32

def log
  # noop
end

#notifyObject



28
29
30
# File 'lib/graphiti_gql/exception_handler.rb', line 28

def notify
  # noop
end