Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ApiProblem/ApiProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ public function __construct($status, $detail, $title = '', $type = '', array $ad
*/
public static function fromException(Exception $exception, $title = '', $type = '', array $additionalDetails = [])
{
return self::fromThrowable($exception, $title, $type, $additionalDetails);
}

/**
* @param Throwable $throwable
* @param string $title
* @param string $type
* @param array $additionalDetails
*
* @return ApiProblem
*/
public static function fromThrowable(Throwable $throwable, $title = '', $type = '', array $additionalDetails = []) {
$eCode = $exception->getCode();
$code = (!empty($eCode) && is_int($eCode)) ? $eCode : 500;

Expand Down
34 changes: 34 additions & 0 deletions src/ApiProblem/ApiProblemResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ public static function fromExceptionToJson(
) {
return new self(new JsonPresenter(ApiProblem::fromException($exception, $title, $type, $additionalDetails)));
}

/**
* @param Throwable $throwable
* @param string $title
* @param string $type
* @param array $additionalDetails
*
* @return ApiProblemResponse
*/
public static function froThrowableToJson(
Throwable $throwable,
$title = '',
$type = '',
array $additionalDetails = []
) {
return new self(new JsonPresenter(ApiProblem::fromThrowable($throwable, $title, $type, $additionalDetails)));
}

/**
* @param $status
Expand Down Expand Up @@ -103,4 +120,21 @@ public static function fromExceptionToXml(
) {
return new self(new XmlPresenter(ApiProblem::fromException($exception, $title, $type, $additionalDetails)));
}

/**
* @param Throwable $throwable
* @param string $title
* @param string $type
* @param array $additionalDetails
*
* @return ApiProblemResponse
*/
public static function fromThroableToXml(
Throwable $throwable,
$title = '',
$type = '',
array $additionalDetails = []
) {
return new self(new XmlPresenter(ApiProblem::fromThrowable($throwable, $title, $type, $additionalDetails)));
}
}