Skip to content

Commit

Permalink
feat: debug 关闭时返回简短的错误提示
Browse files Browse the repository at this point in the history
  • Loading branch information
jiannei committed Mar 12, 2021
1 parent 8a0d99e commit 522de3c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Support/Traits/ExceptionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function prepareJsonResponse($request, Throwable $e)
return app(Response::class)->fail(
'',
$this->isHttpException($e) ? $e->getStatusCode() : 500,
config('app.debug', false) ? $this->convertExceptionToArray($e) : [],
$this->convertExceptionToArray($e),
$this->isHttpException($e) ? $e->getHeaders() : [],
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
);
Expand Down
6 changes: 3 additions & 3 deletions tests/FailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testFailOutController()
$response = Response::fail(
'',
$this->isHttpException($httpException) ? $httpException->getStatusCode() : 500,
config('app.debug', false) ? $this->convertExceptionToArray($httpException) : [],
$this->convertExceptionToArray($httpException),
$this->isHttpException($httpException) ? $httpException->getHeaders() : [],
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
);
Expand All @@ -109,8 +109,8 @@ public function testFailOutController()
'status' => 'fail',
'code' => ResponseCodeEnum::SYSTEM_ERROR,
'message' => ResponseCodeEnum::fromValue(ResponseCodeEnum::SYSTEM_ERROR)->description,
'data' => (object) [],
'error' => config('app.debug', false) ? $this->convertExceptionToArray($httpException) : (object) [],
'data' => (object) [],
'error' => $this->convertExceptionToArray($httpException),
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

$this->assertJsonStringEqualsJsonString($expectedJson, $response->getContent());
Expand Down

0 comments on commit 522de3c

Please sign in to comment.