Skip to content

Commit

Permalink
Added response() function to ApiProblem
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Jan 20, 2022
1 parent 6cade5c commit e351d20
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ApiProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ApiSkeletons\Laravel\ApiProblem\Exception\InvalidArgumentException;
use ApiSkeletons\Laravel\ApiProblem\Exception\ProblemExceptionInterface;
use Exception;
use Illuminate\Http\Response;
use Throwable;

use function array_key_exists;
Expand All @@ -17,6 +18,7 @@
use function get_class;
use function in_array;
use function is_numeric;
use function response;
use function sprintf;
use function strtolower;
use function trim;
Expand Down Expand Up @@ -213,6 +215,16 @@ public function toArray(): array
return array_merge($this->additionalDetails, $problem);
}

/**
* Compose a response and return it.
*/
public function response(): Response
{
return response()
->setStatusCode($this->getStatus())
->setContent($this->toArray());
}

/**
* Set the flag indicating whether an exception detail should include a
* stack trace and previous exception information.
Expand Down

0 comments on commit e351d20

Please sign in to comment.