Added static method fromException() to \KimchiAPI\Objects > Response

This commit is contained in:
Zi Xing 2021-12-15 13:50:31 -05:00
parent a187f280f1
commit dcb1610b81
1 changed files with 19 additions and 0 deletions

View File

@ -4,6 +4,9 @@
namespace KimchiAPI\Objects;
use Exception;
use KimchiRPC\Abstracts\Types\ProtocolType;
class Response
{
/**
@ -108,4 +111,20 @@
return $response_object;
}
/**
* Constructs a response from an exception
* @param Exception $exception
* @return Response
*/
public static function fromException(Exception $exception): Response
{
$response_object = new Response();
$response_object->Success = false;
$response_object->ErrorCode = $exception->getCode();
$response_object->ErrorMessage = $exception->getMessage();
return $response_object;
}
}