Improve error handling for non-json responses