Fix nasty PHP error on line 42 && 119 on invalid credentials

Detect JSON response to prevent PHP errors.