Skip to content

Commit f889df3

Browse files
author
Robert Mosolgo
authored
Merge pull request #3431 from ogidow/fix-error-handlers
Fix find_handler_for method
2 parents a88e865 + b071684 commit f889df3

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

lib/graphql/execution/errors.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def with_error_handling(ctx)
115115
if obj.is_a?(GraphQL::Schema::Object)
116116
obj = obj.object
117117
end
118-
handler.call(err, obj, args, ctx, field)
118+
handler[:handler].call(err, obj, args, ctx, field)
119119
else
120120
raise err
121121
end
@@ -148,11 +148,11 @@ def find_handler_for(error_class)
148148
# If there's an inherited one, but not one defined here, use the inherited one.
149149
# Otherwise, there's no handler for this error, return `nil`.
150150
if parent_handler && handler && parent_handler[:class] < handler[:class]
151-
parent_handler[:handler]
151+
parent_handler
152152
elsif handler
153-
handler[:handler]
153+
handler
154154
elsif parent_handler
155-
parent_handler[:handler]
155+
parent_handler
156156
else
157157
nil
158158
end

spec/graphql/execution/errors_spec.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
require "spec_helper"
33

44
describe "GraphQL::Execution::Errors" do
5-
class ErrorsTestSchema < GraphQL::Schema
5+
class ParentErrorsTestSchema < GraphQL::Schema
6+
class ErrorD < RuntimeError; end
7+
8+
rescue_from(ErrorD) do |err, obj, args, ctx, field|
9+
raise GraphQL::ExecutionError, "ErrorD on #{obj.inspect} at #{field ? "#{field.path}(#{args})" : "boot"}"
10+
end
11+
end
12+
13+
class ErrorsTestSchema < ParentErrorsTestSchema
14+
ErrorD = ParentErrorsTestSchema::ErrorD
615
class ErrorA < RuntimeError; end
716
class ErrorB < RuntimeError; end
817
class ErrorC < RuntimeError
@@ -12,7 +21,6 @@ def initialize(value:)
1221
super
1322
end
1423
end
15-
class ErrorD < RuntimeError; end
1624

1725
class ErrorASubclass < ErrorA; end
1826
class ErrorBChildClass < ErrorB; end
@@ -42,9 +50,6 @@ class ErrorBGrandchildClass < ErrorBChildClass; end
4250
err.value
4351
end
4452

45-
rescue_from(ErrorD) do |err, obj, args, ctx, field|
46-
raise GraphQL::ExecutionError, "ErrorD on #{obj.inspect} at #{field ? "#{field.path}(#{args})" : "boot"}"
47-
end
4853

4954
class Thing < GraphQL::Schema::Object
5055
def self.authorized?(obj, ctx)

0 commit comments

Comments
 (0)