examples/shortenurl.lua
changeset 136 2b04fad2f61a
parent 127 9157566033e8
child 141 1e36a08d7734
--- a/examples/shortenurl.lua	Thu Oct 11 18:11:10 2012 +0300
+++ b/examples/shortenurl.lua	Fri Oct 12 21:24:44 2012 +0300
@@ -48,14 +48,14 @@
 					return true
 				else -- eof
 					local reply = json.decode ( replystring )
-					if reply and reply.id then
+					if ( type ( reply ) == 'table' ) and reply.id then
 						if jid and main.yesno ( main.option ( 'lua_shorten_post_url' ) ) then
 							main.run ( ('say_to -q %s %s'):format ( jid, reply.id ) )
 						else
 							print ( ('Shortened url: %s'):format ( reply.id ) )
 						end
 					else
-						if type ( reply.error ) == 'table' then
+						if type ( reply ) == 'table' and ( type ( reply.error ) == 'table' ) then
 							print ( ('Failed to shorten url: %u %s'):format ( reply.error.code, reply.error.message ) )
 						else
 							print ( ('Failed to shorten url: Unknown response:\n%s'):format ( replystring ) )