added some exception handling to catch IO errors

fixing issue#139

Sinatra is falling down in a daily basis in my server, after some investigation I found out that it was because the IO error.
Not a big change...