-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Db Connected Rest service empty response on http 200. #70
Comments
Turn on Originally posted by @weierophinney at zfcampus/zf-apigility#42 (comment) |
Are you sure there is an error output for json_encode? There are two error functions json_last_error_msg and json_last_error. Even with php errors disabled, the api should return an apiproblem if there is a apiproblem, am i wrong? Originally posted by @fabiocarneiro at zfcampus/zf-apigility#42 (comment) |
In zf-content-negotiation, we have a custom JsonModel, which is the one used by default with services created by Apigility. We use Technically, this should be a rendering error, which should trigger an Originally posted by @weierophinney at zfcampus/zf-apigility#42 (comment) |
I just created a utf8 database, and then added data with some utf8 characters like ã, õ, ... then created a database driver and didn't specified the charset as utf8. I guess it tries to use iso-8859-1 as default, and then json_encode fails with encoding. Adding utf-8 characters is very important, because without it, it will properly encode the json even with wrong chaset. Originally posted by @fabiocarneiro at zfcampus/zf-apigility#42 (comment) |
👍 Originally posted by @olavocneto at zfcampus/zf-apigility#42 (comment) |
@olavocneto this is a very old issue. I actually knew i could configure it, but the error isn't very clarifying. The problem was the error reporting itself. That happens because how json_encode works and this behavior being ignored by apigility. Originally posted by @fabiocarneiro at zfcampus/zf-apigility#42 (comment) |
@fabiocarneiro Yes, I agree. In fact, you helped me. Thank u! Originally posted by @olavocneto at zfcampus/zf-apigility#42 (comment) |
even this is an old issue and I could fix my error with the help of this issue, I have to answer it: @weierophinney: You will get no error if you have active HalJson, no logging no output possibly apigiity can show the same error even HalJson ist active by default. Thank you Originally posted by @Bemazo at zfcampus/zf-apigility#42 (comment) |
Bump Originally posted by @gsomoza at zfcampus/zf-apigility#42 (comment) |
@weierophinney I actually found out my code doesn't use JsonModel. I'm using Apigility + Doctrine (using the api-skeleton libs). By the time the payload gets to the JsonRenderer (Zend View) it's just a plain PHP array, and that piece of code does NOT handle JSON errors whatsoever, which is kind of suprising. Source here: https://github.com/zendframework/zend-view/blob/master/src/Renderer/JsonRenderer.php#L154 Should the system be hydrating a JsonModel instead of using a plain PHP array? Or should the code in JsonRenderer be fixed to throw errors? I lean towards the latter but let me know what you think.. Originally posted by @gsomoza at zfcampus/zf-apigility#42 (comment) |
I've created 3 database tables. City, State, Country. Inserted one row for each of them. Created those 3 db connected rest services, but when i try to use the get method for State, doesn't matter if using the id param or not, it returns empty response with http 200.
Didn't modify anything to any of the services, and the other ones are working. Also tried to delete it and create again. My guess is that its some bug with the service name (State might be a reserved word or something).
Apart from that, couldn't figure out what is going on. Tried to var_dump $collection before the return of RestController and it actually returns the expected collection with one result in it, but couldn't figure out to where this object is returned.
@edit
Figured it out.
json_encode is failing in https://github.com/zendframework/zf2/blob/master/library/Zend/Json/Json.php#L119
with message:
Malformed UTF-8 characters, possibly incorrectly encoded.
which then i figured out that was because my incorrect database adapter charset configuration.
Anyway, it would be very nice to get this json_encode error as a ApiProblem instead of a blank response with http 200.
Originally posted by @fabiocarneiro at zfcampus/zf-apigility#42
The text was updated successfully, but these errors were encountered: