add middleware to convert api errors to json