Handle errors in json format