CLIENT
CLIENT = 'client'
$response : \GuzzleHttp\Psr7\Response
$request : \GuzzleHttp\Psr7\Request
setResponse(\GuzzleHttp\Psr7\Response $response)
Set the associated response
\GuzzleHttp\Psr7\Response | $response | Response |
getResponse() : \GuzzleHttp\Psr7\Response|null
Get the associated response object
setRequest(\GuzzleHttp\Psr7\Request $request)
Set the associated request
\GuzzleHttp\Psr7\Request | $request |
<?php
namespace Obs\Common;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Obs\Log\S3Log;
class ObsException extends \RuntimeException
{
const CLIENT = 'client';
const SERVER = 'server';
/**
* @var Response
*/
protected $response;
/**
* @var Request
*/
protected $request;
/**
* @var string Request ID
*/
protected $requestId;
/**
* @var string Exception type (client / server)
*/
protected $exceptionType;
/**
* @var string Exception code
*/
protected $exceptionCode;
/**
* @var string Exception message
*/
protected $exceptionMessage;
public function __construct ($message = null, $code = null, $previous = null)
{
parent::__construct($message, $code, $previous);
}
/**
* Set the exception code
*
* @param string $code Exception code
*/
public function setExceptionCode($code)
{
$this->exceptionCode = $code;
}
/**
* Get the exception code
*
* @return string|null
*/
public function getExceptionCode()
{
return $this->exceptionCode;
}
public function setExceptionMessage($message)
{
$this->exceptionMessage = $message;
}
public function getExceptionMessage()
{
return $this->exceptionMessage ? $this->exceptionMessage : $this->message;
}
/**
* Set the exception type
*
* @param string $type Exception type
*/
public function setExceptionType($type)
{
$this->exceptionType = $type;
}
/**
* Get the exception type (one of client or server)
*
* @return string|null
*/
public function getExceptionType()
{
return $this->exceptionType;
}
/**
* Set the request ID
*
* @param string $id Request ID
*/
public function setRequestId($id)
{
$this->requestId = $id;
}
/**
* Get the Request ID
*
* @return string|null
*/
public function getRequestId()
{
return $this->requestId;
}
/**
* Set the associated response
*
* @param Response $response Response
*/
public function setResponse(Response $response)
{
$this->response = $response;
}
/**
* Get the associated response object
*
* @return Response|null
*/
public function getResponse()
{
return $this->response;
}
/**
* Set the associated request
*
* @param Request $request
*/
public function setRequest(Request $request)
{
$this->request = $request;
}
/**
* Get the associated request object
*
* @return RequestInterface|null
*/
public function getRequest()
{
return $this->request;
}
/**
* Get the status code of the response
*
* @return int|null
*/
public function getStatusCode()
{
return $this->response ? $this->response->getStatusCode() : -1;
}
/**
* Cast to a string
*
* @return string
*/
public function __toString()
{
$message = get_class($this) . ': '
. 'OBS Error Code: ' . $this->getExceptionCode() . ', '
. 'Status Code: ' . $this->getStatusCode() . ', '
. 'OBS Error Type: ' . $this->getExceptionType() . ', '
. 'OBS Error Message: ' . ($this->getExceptionMessage() ? $this->getExceptionMessage():$this->getMessage());
// Add the User-Agent if available
if ($this->request) {
$message .= ', ' . 'User-Agent: ' . $this->request->getHeaderLine('User-Agent');
}
$message .= "\n";
S3Log::commonLog(INFO, "http request:status:%d, %s",$this->getStatusCode(),"code:".$this->getExceptionCode().", message:".$this->getMessage());
return $message;
}
}