You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with an REST API that responds to a successful DELETE with a 204 and no body (it clearly states this in the response headers with Content-Length: 0)
I found that httpful still tried to parse the response as JSON and falls over in a heap:
Fatal error: Uncaught exception 'Exception' with message 'Unable to parse response as JSON' in phar://C:/Users/colemanb/Documents/Cloud/hpcloud/PHP/lib/httpful.phar/Httpful/Handlers/JsonHandler.php:19
Stack trace:
#0 phar://C:/Users/colemanb/Documents/Cloud/hpcloud/PHP/lib/httpful.phar/Httpful/Response.php(92): Httpful\Handlers\JsonHandler->parse('')
#1 phar://C:/Users/colemanb/Documents/Cloud/hpcloud/PHP/lib/httpful.phar/Httpful/Response.php(41): Httpful\Response->_parse('')
#2 phar://C:/Users/colemanb/Documents/Cloud/hpcloud/PHP/lib/httpful.phar/Httpful/Request.php(174): Httpful\Response->__construct('', 'HTTP/1.1 204 No...', Object(Httpful\Request))
#3 C:\Users\colemanb\Documents\Cloud\hpcloud\PHP\hpcloud-api.php(107): Httpful\Request->send()
#4 C:\Users\colemanb\Documents\Cloud\hpcloud\PHP\demo.php(82): api_call_delete('HPAuth_4fb362aa...', 'https://az-2.re...', '41792484084457', 'servers/123657')
#5 {main} thrown in phar://C:/Users/colemanb/Documents/Cloud/hpcloud/PHP/lib/httpful.phar/Httpful/Handlers/JsonHandler.php on line 19
I got round this by calling autoParse(false) however should the API call error in some way there might be content in the response body that I want to handle. Shouldn't the Response be checked to ensure it's not zero length before invoking the parser? This would make sense to me!
The text was updated successfully, but these errors were encountered:
I'm working with an REST API that responds to a successful DELETE with a 204 and no body (it clearly states this in the response headers with Content-Length: 0)
I found that httpful still tried to parse the response as JSON and falls over in a heap:
I got round this by calling autoParse(false) however should the API call error in some way there might be content in the response body that I want to handle. Shouldn't the Response be checked to ensure it's not zero length before invoking the parser? This would make sense to me!
The text was updated successfully, but these errors were encountered: