Skip to content

Added check for invalid responses which are not empty. #308

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

Merged
merged 2 commits into from
May 1, 2017

Conversation

montymxb
Copy link
Contributor

@montymxb montymxb commented May 1, 2017

This double checks whether a response from the server was decoded successfully. It additionally checks if there was any response to begin with, to avoid false positives on such operations as ParseFile deletion where no response is returned.

This is in regards to #307 , which has pointed out that https://api.parse.com/ now returns a response indicating the service has shut down. This is returned as plain text, however the Content-type indicates application/octet-stream. As a result the sdk tries to process the request to no avail.

Although noone should be using the old api, this makes a point that the sdk could try to run after an invalid response with the 'right' content type. This change prevents that from occurring.

This does not add tests, as this is an unlikely error in how the sdk handles responses. That and the resulting tests would have to target the old api to replicate this, and that may very well be corrected at some point in the future.

@montymxb montymxb requested a review from acinader May 1, 2017 03:30
Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me. one improvement you might consider would be getting the error and logging: http://php.net/manual/en/function.json-last-error.php

@acinader
Copy link
Contributor

acinader commented May 1, 2017

fyi, i sorta accidentally turned on StyleCI when i was futzing with packagist last week. i just disabled it again.

@montymxb
Copy link
Contributor Author

montymxb commented May 1, 2017

@acinader that would be helpful to have a diagnostic message of some sort. There's also json_last_error_msg which could supplement the error code. I'll add that in just a moment here.

Yea probably best to turn that back off, looks the analysis page isn't even reachable :/.

@acinader
Copy link
Contributor

acinader commented May 1, 2017

how about a test :)? If its too much for you to get to, just merge it.

@montymxb
Copy link
Contributor Author

montymxb commented May 1, 2017

I can add a test, but the only way I can see firing this new code is by running it against the old api.parse.com. That would work as a case, but if it's ever corrected we won't have anything to test against :/. Unless we have a special dummy server setup that explicitly returns text with the wrong content type.

I did write a test locally to check this but decided against adding it for the above reason. However in the interest of covering it I can go ahead and add it in? We'll just have to keep an eye on it in case they correct the old api in the future.

@acinader
Copy link
Contributor

acinader commented May 1, 2017

nah, if you tested locally. if you could mock it, but if that isn't easy, i don't think introducing an external dependency is worth it.

@acinader acinader merged commit 7fd04bd into parse-community:master May 1, 2017
@montymxb
Copy link
Contributor Author

montymxb commented May 1, 2017

I'll keep a thought on it. There's probably a way to mock up something more reliable... I'll see if I can't come up with something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants