Skip to content

Commit e351d20

Browse files
committed
Added response() function to ApiProblem
1 parent 6cade5c commit e351d20

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/ApiProblem.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use ApiSkeletons\Laravel\ApiProblem\Exception\InvalidArgumentException;
88
use ApiSkeletons\Laravel\ApiProblem\Exception\ProblemExceptionInterface;
99
use Exception;
10+
use Illuminate\Http\Response;
1011
use Throwable;
1112

1213
use function array_key_exists;
@@ -17,6 +18,7 @@
1718
use function get_class;
1819
use function in_array;
1920
use function is_numeric;
21+
use function response;
2022
use function sprintf;
2123
use function strtolower;
2224
use function trim;
@@ -213,6 +215,16 @@ public function toArray(): array
213215
return array_merge($this->additionalDetails, $problem);
214216
}
215217

218+
/**
219+
* Compose a response and return it.
220+
*/
221+
public function response(): Response
222+
{
223+
return response()
224+
->setStatusCode($this->getStatus())
225+
->setContent($this->toArray());
226+
}
227+
216228
/**
217229
* Set the flag indicating whether an exception detail should include a
218230
* stack trace and previous exception information.

0 commit comments

Comments
 (0)