API errors not returning error codes


#1

My application is sending regular posts to /1/statuses/update.json and once in a while I get errors for duplicated messages or too long tweets or something else that is not a problem with the user account authorization.

I would like to be able to gracefully handle these errors that may be bugs in my application.

I see in the documentation that error messages should be returning an error code number but I am never getting these error codes. I just get the error message text, which I would rather not try you process because it comes in the user language.

Am I doing something wrong that is making the error code numbers not be returned? Here follows a sample of an API request log with all headers.

[14-Sep-2012 04:25:07] Connecting to api.twitter.com
[14-Sep-2012 04:25:07] Resolving HTTP server domain “api.twitter.com”…
[14-Sep-2012 04:25:07] Connecting to HTTP server IP 199.59.148.20 port 443…
[14-Sep-2012 04:25:08] Connected to api.twitter.com
[14-Sep-2012 04:25:08] C POST /1/statuses/update.json HTTP/1.1
[14-Sep-2012 04:25:08] C Host: api.twitter.com
[14-Sep-2012 04:25:08] C User-Agent: httpclient (http://www.phpclasses.org/httpclient $Revision: 1.89 $)
[14-Sep-2012 04:25:08] C Accept: /
[14-Sep-2012 04:25:08] C Authorization: OAuth oauth_consumer_key=“58oel5tI85BBh0s7ZXUSQ”,oauth_nonce=“916862f84a23ac6424f20f5297b56afd”,oauth_signature_method=“HMAC-SHA1”,oauth_timestamp=“1347607507”,oauth_version=“1.0”,oauth_token=“19577610-wn7c7ZSkmkdpreoP7hGxiiSkGzXDjS8SaIRKFZn1W”,status=“Some%20very%20long%20message%2C%20that%20goes%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on%20and%20on”,oauth_signature=“yi9ElMKSVxNSQ4D%2FU8OFxqrBSjU%3D”
[14-Sep-2012 04:25:08] C Connection: Keep-Alive
[14-Sep-2012 04:25:08] C Content-Type: application/x-www-form-urlencoded
[14-Sep-2012 04:25:08] C Content-Length: 227
[14-Sep-2012 04:25:08] C
[14-Sep-2012 04:25:08] C status=Some+very+long+message%2C+that+goes+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on+and+on
[14-Sep-2012 04:25:08] S HTTP/1.1 403 Forbidden
[14-Sep-2012 04:25:08] S Date: Fri, 14 Sep 2012 07:25:08 GMT
[14-Sep-2012 04:25:08] S Status: 403 Forbidden
[14-Sep-2012 04:25:08] S Content-Length: 81
[14-Sep-2012 04:25:08] S X-Transaction: 3d9e80aefb10b849
[14-Sep-2012 04:25:08] S X-MID: f556632b89e839c62244ad412ec8fdac71f04183
[14-Sep-2012 04:25:08] S X-Access-Level: read-write
[14-Sep-2012 04:25:08] S Pragma: no-cache
[14-Sep-2012 04:25:08] S Last-Modified: Fri, 14 Sep 2012 07:25:08 GMT
[14-Sep-2012 04:25:08] S X-Transaction-Mask: a6183ffa5f8ca943ff1b53b5644ef1147cbe5a79
[14-Sep-2012 04:25:08] S X-Frame-Options: SAMEORIGIN
[14-Sep-2012 04:25:08] S Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
[14-Sep-2012 04:25:08] S Content-Type: application/json; charset=utf-8
[14-Sep-2012 04:25:08] S X-Runtime: 0.08894
[14-Sep-2012 04:25:08] S Expires: Tue, 31 Mar 1981 05:00:00 GMT
[14-Sep-2012 04:25:08] S Set-Cookie: k=10.35.24.121.1347607508580449; path=/; expires=Fri, 21-Sep-12 07:25:08 GMT; domain=.twitter.com
[14-Sep-2012 04:25:08] S Set-Cookie: guest_id=v1%3A134760750858593075; domain=.twitter.com; path=/; expires=Sun, 14-Sep-2014 19:25:08 GMT
[14-Sep-2012 04:25:08] S Set-Cookie: dnt=; domain=.twitter.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
[14-Sep-2012 04:25:08] S Set-Cookie: lang=en; path=/
[14-Sep-2012 04:25:08] S Set-Cookie: lang=en; path=/
[14-Sep-2012 04:25:08] S Set-Cookie: lang=en; path=/
[14-Sep-2012 04:25:08] S Set-Cookie: twid=u%3D19577610%7CS2Sh7qHAKamd9PCk7jg0vnaGBqY%3D; domain=.twitter.com; path=/; secure
[14-Sep-2012 04:25:08] S Set-Cookie: _twitter_sess=BAh7CToPY3JlYXRlZF9hdGwrCHa2qsM5AToMY3NyZl9pZCIlODZmNjZjZGZk%250AYTU5ZDVkYTMxODE1ODM2ZTMxNjk3NTEiCmZsYXNoSUM6J0FjdGlvbkNvbnRy%250Ab2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA6B2lkIiViZWY4%250AYWZjOTExODU0N2RiOGVjNGU2MjM0ODlhODc5Yg%253D%253D–b2f5d950459703b418f68f5369b3bf2a306314d6; domain=.twitter.com; path=/; HttpOnly
[14-Sep-2012 04:25:08] S Vary: Accept-Encoding
[14-Sep-2012 04:25:08] S Server: tfe
[14-Sep-2012 04:25:08] S
[14-Sep-2012 04:25:08] S {“error”:“Status is over 140 characters.”,“request”:"/1/statuses/update.json"}