Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch_exception within a Error set as a potential_error on a LookupArgumentSet does not work #7

Open
jimeh opened this issue Apr 23, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@jimeh
Copy link
Contributor

jimeh commented Apr 23, 2021

Error objects which use catch_exception statements, only actually catch the
exception if it is set as a potential_error on a Endpoint.

Within a LookupArgumentSet that specify potential_error, no errors defined by
catch_exception raised within the LookupArgumentSet resolver are caught.

Below is a rough example of the issue:

class Book < Rapid::Object
  field :id, :string
  field :name, :string
end

class TimeoutError < Rapid::Error
  code :timeout_error
  catch_exception Faraday::TimeoutError
end

class BookLookup < Rapid::LookupArgumentSet
  name 'Book Lookup'
  argument :id, :string

  potential_error TimeoutError

  resolver do |set, request, service|
    Faraday.get("http://foo/bar/#{set[:id]}").parsed_body
  end
end

class BookGet < Rapid::Endpoint
  name 'Get book info'

  argument :book, BookLookup, required: true
  field :book, Book

  def call
    book = request.arguments[:book].resolve
    response.add_field :book, book
  end
end

If the BookLookup resolver raises a Faraday::Timeout error, it is not captured
and Rapid returns a unhandled_exception error code instead of the custom
timeout_error.

Adding potential_error TimeoutError on the Endpoint itself fixes the issue,
but obviously it would be better if the LookupArgumentSet resolver captured all
errors relevant to the LookupArgumentSet.

@jimeh jimeh added the bug Something isn't working label Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant