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've been testing Rack::Lint locally and we have a lot of issues in our spec suite. I'll open issues for others but let's start with this one:
Running spec: spec/grape/api_spec.rb:2341.
Rack::Lint::LintError:
a header value must be a String or Array of Strings, but the value of 'content-type' is a NilClass
This test is using rack_response directly in a rescue_from like this
subject.rescue_fromApiSpec::APIErrors::ParentError,rescue_subclasses: truedo |e|
rack_response("rescued from #{e.class.name}",500)end
Unfortunately, rack_response doesn't act like error! since the last is passing through the formatting part (because of the throw) whereas the rack_response just html escaped if content_type is set totext/html (if content_type is set in the api)
Finally, rack_response is never mentioned in the README but using a plain Rack::Response is. Also, Using rack_response or Rack::Response doesn't pass through the formatting part of the error middleware since its considered a final response.
IMO, there are many ways to solve that but I found an interesting middleware within Rack called [Rack::ContentType] (https://github.com/rack/rack/blob/main/lib/rack/content_type.rb) that will set a default content-type header if needed. Default, is text/html but I think text/plain would be more appropriate since we do not need to escape. I think its a clean way to deal with that issue and we could remove some default behavior in the code.
The text was updated successfully, but these errors were encountered:
Now, some test are now using rack_response instead of error! and this method will call content-type from the endpoint which will be nil if not set explicitely from header.
I don't think anyone is using rack_response in a rescue_from since its never been documented and I think we should
1 - remove the method from inside_route
2 - make the function private in lib/grape/middleware/error.rb, even though its not accessible anymore within rescue_from
I've been testing Rack::Lint locally and we have a lot of issues in our spec suite. I'll open issues for others but let's start with this one:
Running spec: spec/grape/api_spec.rb:2341.
This test is using
rack_response
directly in a rescue_from like thisUnfortunately,
rack_response
doesn't act likeerror!
since the last is passing through the formatting part (because of thethrow
) whereas therack_response
just html escaped if content_type is set totext/html
(if content_type is set in the api)Finally,
rack_response
is never mentioned in the README but using a plainRack::Response
is. Also, Usingrack_response
orRack::Response
doesn't pass through the formatting part of theerror
middleware since its considered a final response.IMO, there are many ways to solve that but I found an interesting middleware within Rack called [Rack::ContentType] (https://github.com/rack/rack/blob/main/lib/rack/content_type.rb) that will set a default content-type header if needed. Default, is
text/html
but I thinktext/plain
would be more appropriate since we do not need to escape. I think its a clean way to deal with that issue and we could remove somedefault
behavior in the code.The text was updated successfully, but these errors were encountered: