handle json responses and text responses