Make the error return semantics more consistent and Lua-style

- API functions now return: <json_data>, <headers>, [tname]
- on error they'll return: nil, <error>, [headers]
- the 'error' value can be a string (socket error) or a table (API error)
- functions no longer return status_line or result_code