Avnish1985 / bitly-api

Automatically exported from code.google.com/p/bitly-api
0 stars 0 forks source link

Invalid JSON call to Shorten endpoint produces bad formated response #29

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem (provide an exact http api call where
appropriate)?

1. I call the endpoint with a invalid parameter, for example
http://api.bit.ly/v3/shorten?login=digiogo&apiKey=e73334a3ee6bed79705612c&longUr
l=dasdhttp://www.fiap.com.br&format=json
2. According to the API documentation I'd receive the response with data member 
as NULL, but it returns an empty array instead.

What is the expected output?
{ "data": null, "status_code": 500, "status_txt": "INVALID_URI" }

What do you see instead?
{ "data": [ ], "status_code": 500, "status_txt": "INVALID_URI" }

What version of the product are you using? On what operating system?
v3

Original issue reported on code.google.com by digi...@gmail.com on 25 Nov 2010 at 11:42

GoogleCodeExporter commented 8 years ago
the value of "data" when status_code != 200 should be treated as undefined (ie: 
you should not depend on any specific value to catch errors). we will update 
our documentation to reflect that.

Original comment by jehiah on 29 Nov 2010 at 3:48

GoogleCodeExporter commented 8 years ago
Yes, I've understood your explanation about what I should do to identify any 
error (status_code != 200) in my app. 
However I think I haven't explained exactly what the problem is. 

Actually, the issue is: two different types in the return of Shorten JSON 
endpoint. 
When I receive a successful reponse(staus code = 200) the method returns an 
'simple' Object, but when any error happens the method return an empty Object 
Array - a completely different type of return. 
And it happens only in Shorten endpoint. 
For example, if you call 
http://api.bit.ly/v3/info?login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d
71bf07&format=json the response will be an 500 error with data member as NULL.
On the other hand, calling 
http://api.bit.ly/v3/shorten?login=digiogo&apiKey=e73334a3ee6bed79705612c&longUr
l=dasdhttp://www.fiap.com.br&format=json generates the same error 500, but data 
member will be [ ]. 

If data member was an array in well-succeded responses, there wouldn't be any 
problem.
Could you understand my view about the issue? 
If you agree with me, please modify that...

Original comment by digi...@gmail.com on 6 Dec 2010 at 6:25

GoogleCodeExporter commented 8 years ago
It totally sucks that the json type changes depending on the the value of 
another key. You cannot use any json library properly in non-script languages 
like java or c#.

Original comment by alain.ad...@gmail.com on 15 Jul 2013 at 8:50