활성 리소스 find()
호출이 일반적인 HTTP 200 대신 HTTP 206을 반환했음을 어떻게 감지합니까?Rails ActiveResource가 HTTP 206 응답 코드를 감지했습니다.
저는 ActiveResource가 HTTP 3xx-5xx 응답 코드에 대한 다양한 예외를 throw하지만, 어떤 200 수준 응답 코드를 수신했는지 파악할 수 있습니까?
활성 리소스 find()
호출이 일반적인 HTTP 200 대신 HTTP 206을 반환했음을 어떻게 감지합니까?Rails ActiveResource가 HTTP 206 응답 코드를 감지했습니다.
저는 ActiveResource가 HTTP 3xx-5xx 응답 코드에 대한 다양한 예외를 throw하지만, 어떤 200 수준 응답 코드를 수신했는지 파악할 수 있습니까?
스레드에 대한 마지막 응답을받는 방법은 Active Resource responses, how to get them을 참조하십시오. 필요에 따라 다음 응답 코드를 테스트 할 수 있습니다
class MyConn < ActiveResource::Connection
def handle_response(resp)
# Store in thread (thanks fivell for the tip).
# Use a symbol to avoid generating multiple string instances.
Thread.current[:active_resource_connection_last_response] = resp
super
end
# this is only a convenience method. You can access this directly from the current thread.
def last_resp
Thread.current[:active_resource_connection_last_response]
end
end
class MyResource < ActiveResource::Base
class << self
attr_writer :connection
end
end
myconn = MyConn.new MyResource.connection.site
MyResource.connection = myconn # replace with our enhanced version
object = MyResource.find(id)
response_code = MyResource.last_resp.code
https://github.com/Fivell/activeresource-response 이제이 밖으로 노력이 보석 – Fivell