public function __construct($fieldname, $msg = null) { $this->fieldname = $fieldname; if ($msg === null) { // TRANS: Exception text shown when no uploaded media was provided in POST // TRANS: %s is the HTML input field name. $msg = sprintf(_('There is no uploaded media for input field "%s".'), $this->fieldname); } parent::__construct($msg, 400); }
/** * Request the creation of a new Order with the given arrays. * * @param array|Item[] $items * @param array|ShippingOption[] $shippingOptions * @return array */ public function newOrder(array $items, array $shippingOptions) { /* * Prepare the JSON POST data. */ $data = json_encode(['orderItems' => $items, 'orderShippingOptions' => $shippingOptions]); /* * Set the request headers. */ $headers = ['POST /v' . self::API_VERSION . '/checkouts HTTP/1.1', 'Host: ' . self::API_URL, 'Authorization: ' . $this->authorizationKey, 'Content-Type: application/json', 'Content-Length: ' . strlen($data)]; /* * Init cURL with the POST data and headers. */ $curl = curl_init($this->getSecureUrl('checkouts')); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); /* * Fire in the hole. */ $response = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); /* * Look for validation or other unsuspected errors. */ switch ($httpCode) { case 401: throw new ClientException('We could not authenticate you, our dolphins guess that your authorization key is invalid.'); case 400: $exception = new ClientException('There were some problems with your input.'); $exception->setErrors(json_decode($response, true)['errors']['0']['detail']); return $exception; case 500: throw new ClientException('There is something unusual going on on our servers. Please try again later.'); } return json_decode($response)->data->redirectUrl; }
/** * Adds an array of parsed message values to the standard exception */ public function __construct(array $parsedMsgArr, $msg, $errno, \Exception $previousException = null) { $this->parsedMsgArr = $parsedMsgArr; /** @noinspection PhpParamsInspection */ parent::__construct($msg, $errno, $previousException); }
/** * @param string $clientMessage */ public function __construct($clientMessage) { parent::__construct(sprintf('The submitted FTP credentials form returned with an error: %s.', empty($clientMessage) ? '(empty)' : $clientMessage)); $this->clientMessage = $clientMessage; }
/** * @param mixed $requestId * @param mixed $responseId */ public function __construct($requestId, $responseId) { $message = "The request and response ID's do not match [\"RequestID\"=>%s, \"ResponseID\"=>%s]"; $message = sprintf($message, var_export($requestId, true), var_export($responseId, true)); parent::__construct($message); }
public function __construct(array $errors = [], $message = "", $code = 0, Exception $previous = null) { $this->errors = $errors; parent::__construct(422, $message, $code, $previous); }
public function __construct($errorMessage, $errorCode) { parent::__construct($errorMessage, $errorCode); $this->setErrorType("Server"); }
public function __construct($field) { parent::__construct(sprintf(self::MESSAGE, $field)); }
/** *send a query to the CouchDB server * * In a continuous query, the server send headers, and then a JSON object per line. * On each line received, the $callable callback is fired, with two arguments : * * - the JSON object decoded as a PHP object * * - a Client instance to use to make queries inside the callback * * If the callable returns the boolean FALSE , continuous reading stops. * * @param callable $callable PHP function name / callable array ( see http://php.net/is_callable ) * @param string $method HTTP method to use (GET, POST, ...) * @param string $url URL to fetch * @param array $parameters additionnal parameters to send with the request * @param string|array|object $data request body * * @return string|false server response on success, false on error * * @throws Exception|InvalidArgumentException|ClientException|NoResponseException */ public function continuousQuery($callable, $method, $url, $parameters = array(), $data = null) { if (!in_array($method, $this->HTTP_METHODS)) { throw new Exception("Bad HTTP method: {$method}"); } if (!is_callable($callable)) { throw new \InvalidArgumentException("callable argument have to success to is_callable PHP function"); } if (is_array($parameters) and count($parameters)) { $url = $url . '?' . http_build_query($parameters); } //Send the request to the socket $request = $this->_socket_buildRequest($method, $url, $data, null); if (!$this->_connect()) { return FALSE; } fwrite($this->socket, $request); //Read the headers and check that the response is valid $response = ''; $headers = false; while (!feof($this->socket) && !$headers) { $response .= fgets($this->socket); if ($response == "HTTP/1.1 100 Continue\r\n\r\n") { $response = ''; continue; } elseif (preg_match("/\r\n\r\n\$/", $response)) { $headers = true; } } $headers = explode("\n", trim($response)); $split = explode(" ", trim(reset($headers))); $code = $split[1]; unset($split); //If an invalid response is sent, read the rest of the response and throw an appropriate ClientException if (!in_array($code, array(200, 201))) { stream_set_blocking($this->socket, false); $response .= stream_get_contents($this->socket); fclose($this->socket); throw ClientException::factory($response, $method, $url, $parameters); } //For as long as the socket is open, read lines and pass them to the callback $c = clone $this; while ($this->socket && !feof($this->socket)) { $e = NULL; $e2 = NULL; $read = array($this->socket); if (false === ($num_changed_streams = stream_select($read, $e, $e2, 1))) { $this->socket = null; } elseif ($num_changed_streams > 0) { $line = fgets($this->socket); if (strlen(trim($line))) { $break = call_user_func($callable, json_decode($line), $c); if ($break === FALSE) { fclose($this->socket); } } } } return $code; }
/** * @param string $reason */ public function __construct($reason) { parent::__construct('Extension installation failed: ' . $reason); $this->reason = $reason; }
function __construct($reason, $retryAfter, $params) { $this->retryAfter = (int) $retryAfter; parent::__construct($reason, 503, null, "MAINTENANCE", $params); }
public function __construct($number) { parent::__construct(sprintf(self::MESSAGE, $number)); }
/** * @param int $code * @param string $message * @param null $data */ public function __construct($code, $message, $data = null) { parent::__construct($message, $code); $this->data = $data; }
public function __construct($qmkey) { $this->qmkey = $qmkey; parent::__construct(_('Bad queue manager key was used.')); }
public function __construct() { parent::__construct('There is no service available for this expedition.'); }
public function __construct($vals = null) { if (!isset(self::$_TSPEC)) { self::$_TSPEC = array(1 => array('var' => 'code', 'type' => TType::I32), 2 => array('var' => 'what', 'type' => TType::STRING)); } if (is_array($vals)) { if (isset($vals['code'])) { $this->code = $vals['code']; } if (isset($vals['what'])) { $this->what = $vals['what']; } } }
function __construct() { parent::__construct(array('status_message' => 'No response from server - ')); }
public function __construct($message = "", $code = 0, Exception $previous = null) { parent::__construct(410, $message, $code, $previous); }
/** * ServerException constructor. * @param string $errorMessage * @param string $errorCode * @param int $httpStatus * @param int $code */ public function __construct($errorMessage, $errorCode, $httpStatus = 0, $code = 0) { parent::__construct($errorMessage, $errorCode, $httpStatus, $code); $this->setErrorType('Server'); }
/** * @param string $msg * @param int $code * @param Exception $previous */ public function __construct($msg = '', $code = 404, Exception $previous = null) { parent::__construct($msg, $code, $previous); }
public function __construct($retryAfter, $rateLimit = 0, $message = '', $code = 0, Exception $previous = null) { $this->retryAfter = $retryAfter; $this->rateLimit = (int) $rateLimit; parent::__construct(429, $message, $code, $previous); }
/** * @param int $errno The connection error code * @param string $errstr The connection error message */ public function __construct($errno, $errstr) { parent::__construct(sprintf('Socket error %d: %s', $errno, $errstr)); }
/** * Constructor * * @param string $message Message for the exception */ public function __construct($message = null) { parent::__construct($message, 403); }
function __construct($msg = null, $code = 400) { if ($msg === null) { $msg = $this->defaultMessage(); } parent::__construct($msg, $code); }
public function __construct($zipCode, $city) { parent::__construct(sprintf(self::MESSAGE, $zipCode, $city)); }
/** * Setup the exception * * @since 2.0 * @param string $message error message * @param int $code HTTP response code * @param stdClass $request request class * @param stdClass $response response class */ public function __construct($message, $code = 0, $request, $response) { parent::__construct($message, $code); $this->request = $request; $this->response = $response; }
public function __construct($path) { parent::__construct('Could not find file: ' . $path); }