extracting out common logic of success/error
implementation of transformResponse