Posts

Showing posts from January, 2012

REST api: please don't return 200 OK for errors

Please when building REST api do not return 200 OK if there is actually an error. Too many REST apis return 200 OK but with a field such as success or status that is used to indicate if there was actually an error or not! e.g. a json example if error: {"success": "false", "error": "sorry that key already exists"} and if all is ok: {"success": "true", [{...}, {...} ]} In both cases 200 OK is returned from server. There's no need to do that. As a client side developer I need to then have code within my Rest api call success handler that checks the "success" field to determine if the request really succeeded or not. Libraries such as jQuery v1.5 now allow me to specify handlers based on HTTP response codes so it's much cleaner if I get a useful HTTPS response back. As much as possible, please just use the HTTP response codes instead. If all went ok then just return 200 OK with any response

Exception thrown without a stack frame in Unknown on line 0

We got this tricky error a few days before a big deadline (typical) "Exception thrown without a stack frame in Unknown on line 0" We were able to find the cause thanks to others who have posted about this problem. Basically after php has finished executing something went wrong. For us it turns out a SimpleXML node was persisted in the session and that caused the session save to fail. We debugged the problem using php session_encode() which converts the session to a string which we then echo-ed and we saw "SimpleXMLElement":0:{}" in the string (bad). SimpleXMLElement is a reference and you can't store that in session. In our case we should never have stored it in the session in the first place so we just deleted that code, but if you had to put into session then you should convert it to a simple type first e.g. cast to string (string). Hope this helps you as others helped us!