$text, 'mode' => $mode, 'context' => $context ) ) ); // Send the request. $response = $this->client->post($this->fetchUrl($path), $data); // Validate the response code. if ($response->code != 200) { // Decode the error response and throw an exception. $error = json_decode($response->body); $message = (isset($error->message)) ? $error->message : 'Error: ' . $response->code; throw new DomainException($message, $response->code); } return $response->body; } }