Skip to content

Commit

Permalink
feat: Add config for fail http status #19
Browse files Browse the repository at this point in the history
  • Loading branch information
jiannei committed Mar 20, 2021
1 parent fabd99b commit 136d7cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion config/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,42 @@
return [
'enum' => \Jiannei\Enum\Laravel\Repositories\Enums\HttpStatusCodeEnum::class,

'error_code' => \Jiannei\Enum\Laravel\Repositories\Enums\HttpStatusCodeEnum::HTTP_INTERNAL_SERVER_ERROR,
/*
|--------------------------------------------------------------------------
| Set the http status code when the response fails
|--------------------------------------------------------------------------
|
| the reference options are false, 200, 500
|
| false, stricter http status codes such as 404, 401, 403, 500, etc. will be returned
| 200, All failed responses will also return a 200 status code
| 500, All failed responses return a 500 status code
*/

'error_code' => false,

// Set the http status code returned when the form validation fails.
// When the error_code is set to 200 or 500, it will not work

'validation_error_code' => \Jiannei\Enum\Laravel\Repositories\Enums\HttpStatusCodeEnum::HTTP_UNPROCESSABLE_ENTITY,

// Set the structure of the paging data return,the following structure will be returned by default,
// You can modify the name of the inner data field through the following configuration items, such as rows or list
//{
// "status": "success",
// "code": 200,
// "message": "Success.",
// "data": {
// "data": [
// // ...
// ],
// "meta": {
// // ...
// }
// },
// "error": {}
//}

'format' => [
'paginated_resource' => [
'data_field' => 'data',
Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function fail(string $message = '', int $code = 500, $errors = null, arra
{
$response = $this->response(
$this->formatData(null, $message, $code, $errors),
Config::get('response.error_code', $code),
Config::get('response.error_code') ?: $code,
$header,
$options
);
Expand Down

0 comments on commit 136d7cc

Please sign in to comment.