added bad request exception and json error check for request

Please have a look at the code . If it's wrong or corrections to be done. Let me know.