control all the errors & respond as json