Skip to content

Commit 136d7cc

Browse files
author
jiannei
committed
feat: Add config for fail http status #19
1 parent fabd99b commit 136d7cc

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

config/response.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,42 @@
1212
return [
1313
'enum' => \Jiannei\Enum\Laravel\Repositories\Enums\HttpStatusCodeEnum::class,
1414

15-
'error_code' => \Jiannei\Enum\Laravel\Repositories\Enums\HttpStatusCodeEnum::HTTP_INTERNAL_SERVER_ERROR,
15+
/*
16+
|--------------------------------------------------------------------------
17+
| Set the http status code when the response fails
18+
|--------------------------------------------------------------------------
19+
|
20+
| the reference options are false, 200, 500
21+
|
22+
| false, stricter http status codes such as 404, 401, 403, 500, etc. will be returned
23+
| 200, All failed responses will also return a 200 status code
24+
| 500, All failed responses return a 500 status code
25+
*/
26+
27+
'error_code' => false,
28+
29+
// Set the http status code returned when the form validation fails.
30+
// When the error_code is set to 200 or 500, it will not work
1631

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

34+
// Set the structure of the paging data return,the following structure will be returned by default,
35+
// You can modify the name of the inner data field through the following configuration items, such as rows or list
36+
//{
37+
// "status": "success",
38+
// "code": 200,
39+
// "message": "Success.",
40+
// "data": {
41+
// "data": [
42+
// // ...
43+
// ],
44+
// "meta": {
45+
// // ...
46+
// }
47+
// },
48+
// "error": {}
49+
//}
50+
1951
'format' => [
2052
'paginated_resource' => [
2153
'data_field' => 'data',

src/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function fail(string $message = '', int $code = 500, $errors = null, arra
145145
{
146146
$response = $this->response(
147147
$this->formatData(null, $message, $code, $errors),
148-
Config::get('response.error_code', $code),
148+
Config::get('response.error_code') ?: $code,
149149
$header,
150150
$options
151151
);

0 commit comments

Comments
 (0)