You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm seeing an issue with swiftype-rb, a Ruby wrapper for the Swiftype hosted search engine built on faraday. On digging through the stack trace however and seeing #161 and #69, I assume though that the reason for the exception might have it's roots in the Faraday setup of swiftype-rb.
Here's a screenshot of the last stacktrack (done with better_errors).
After some experiments I can tell that having one of these characters ( ) , ? in the string will raise the shown exception, while an included . will do no harm.
After reading the mentioned issues I think the reason might lie somewhere in the middleware structuring. It would be nice if someone could have a look at this Connection class of swiftype-rb, especially at the used middleware.
moduleSwiftypemoduleConnectionincludeSwiftype::Requestdefconnectionraise(InvalidCredentials,"You must supply credentials to Swiftype.configure")unless(Swiftype.username && Swiftype.password) || Swiftype.api_key@connection ||= beginconn=Faraday.new(Swiftype.endpoint)do |b|
b.response:raise_errorb.useFaraday::Request::UrlEncodedb.useFaradayMiddleware::ParseJsonb.useFaradayMiddleware::Mashifyb.useApiResponseMiddlewareb.adapterFaraday.default_adapterendconn.basic_authSwiftype.username,Swiftype.passwordifSwiftype.username && Swiftype.passwordconn.headers['User-Agent']=Swiftype.user_agentconnendendclassApiResponseMiddleware < Faraday::Response::Middlewaredefon_complete(env)caseenv[:status]when200,201,204nilwhen401raiseInvalidCredentialswhen404raiseNonExistentRecordwhen409raiseRecordAlreadyExistselseraiseUnexpectedHTTPException,env[:body]endenddefinitialize(app)super@parser=nilendendendend
Could the error be a result of the middleware structure, or would you recommend digging somewhere else?
Thanks for any feedback in advance!
Best regards,
Thomas
The text was updated successfully, but these errors were encountered:
Faraday's builder uses a stack. Requests start at the top and work their way down. You typically put stuff that modifies the request first (anything that tweaks the headers, prepares the body, etc). Then the response middleware works with the adapter's response before Faraday returns it to your application.
Try re-arranging the stack to something like this:
conn=Faraday.new(Swiftype.endpoint)do |b|
#b.use Faraday::Request::UrlEncodedb.request:url_encodedb.adapterFaraday.default_adapter# raise early...b.response:raise_error# then parse the body json to a hash...b.useFaradayMiddleware::ParseJson# then turn the hash into a mashify objectb.useFaradayMiddleware::Mashify# not sure what this is, but I'm assuming it expects a mashify objectb.useApiResponseMiddlewareend
Make sense?
This has turned out to be a confusing aspect of Faraday, so we're likely changing it for Faraday v1.0 so you can add the middleware in any order.
Hey everyone,
I'm seeing an issue with swiftype-rb, a Ruby wrapper for the Swiftype hosted search engine built on faraday. On digging through the stack trace however and seeing #161 and #69, I assume though that the reason for the exception might have it's roots in the Faraday setup of swiftype-rb.
Here's a screenshot of the last stacktrack (done with better_errors).
After some experiments I can tell that having one of these characters
( ) , ?
in the string will raise the shown exception, while an included.
will do no harm.After reading the mentioned issues I think the reason might lie somewhere in the middleware structuring. It would be nice if someone could have a look at this Connection class of swiftype-rb, especially at the used middleware.
Could the error be a result of the middleware structure, or would you recommend digging somewhere else?
Thanks for any feedback in advance!
Best regards,
Thomas
The text was updated successfully, but these errors were encountered: