From 83ab9eff31f7ce7bd5a02947b99ae1949d07f0fc Mon Sep 17 00:00:00 2001 From: denisqin Date: Fri, 8 Feb 2019 15:46:06 +0300 Subject: [PATCH] Added errors in apidoc --- .../ResponseStrategies/ResponseTagStrategy.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Tools/ResponseStrategies/ResponseTagStrategy.php b/src/Tools/ResponseStrategies/ResponseTagStrategy.php index 913a117e..5bd10ad6 100644 --- a/src/Tools/ResponseStrategies/ResponseTagStrategy.php +++ b/src/Tools/ResponseStrategies/ResponseTagStrategy.php @@ -5,6 +5,7 @@ use Illuminate\Routing\Route; use Illuminate\Http\JsonResponse; use Mpociot\Reflection\DocBlock\Tag; +use App\Error; /** * Get a response from the docblock ( @response ). @@ -43,10 +44,14 @@ protected function getDocBlockResponses(array $tags) } return array_map(function (Tag $responseTag) { - preg_match('/^(\d{3})?\s?([\s\S]*)$/', $responseTag->getContent(), $result); - - $status = $result[1] ?: 200; - $content = $result[2] ?: '{}'; + preg_match('/^(sys_([\d]{2}))?\s?(\d{3})?\s?([\s\S]*)$/', $responseTag->getContent(), $result); + if ($result[1]) { + $error = Error::where(['code' => $result[1]])->first(); + $content = $error ?: '{}'; + } else { + $content = $result[3] ?: '{}'; + } + $status = $result[2] ?: 200; return new JsonResponse(json_decode($content, true), (int) $status); }, $responseTags);