-
Notifications
You must be signed in to change notification settings - Fork 26
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
Handle empty array as a response in .first #70
Conversation
@@ -62,7 +62,9 @@ def all(conditions = {}) | |||
|
|||
# Retrieve a single resource. See usage comment on .all | |||
def first(conditions = {}) | |||
new(conditions.merge(Connection.get(create_route(:get, conditions)).body['data'])) | |||
data = Connection.get(create_route(:get, conditions)).body['data'] | |||
data = {} if data.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get a comment
Honestly I don't think we should call in my experience SG usually returns a bad status when you request a resource that doesn't exist... you are saying that in the case of I believe you because I have never actually used the |
cc @jarthod |
Indeed to would be better to raise here, it's weird if sgizmo returns a 200 for that. I'm interested in the debug output too. |
Here is the debug output. The contact in this situation belongs to the specified survey, but it is the wrong campaign. I can resubmit with a raise if you prefer, let me know what you think! |
ugh yeah that sucks.
|
Ok they suck, as always. But with your fix in this case what would be returned by |
we should raise an exception |
i would probably put the exception in the response parser - basically i don't think but also make sure you add a spec for this behavior. |
Glad we agree haha. I'll resubmit with an exception in a bit. Thanks! |
Closing this PR because this isn't getting merged in this form, but opened an issue about it if someone wants to fix it in a more universal way #81 |
I ran into this issue when querying the API for a Contact that did not exist using .first. The data in the body was returning an empty array rather than a hash in this case.