dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.33k stars 1.25k forks source link

What's difference between code and status_code? How can I set code? #1576

Closed imageslr closed 6 years ago

imageslr commented 6 years ago
Q A
Bug? no
New Feature? no
Framework Laravel
Framework version 5.x.y
Package version 1.x.y
PHP version 7.x.y

Expected Behaviour

I want to set my own code for a response, such as:

{
  "status_code": 400,
  "code": 1100,
  "message": "xxxx"
}

and I found there was a :code attr in config/api.php:

'errorFormat' => [
        'message' => ':message',
        'errors' => ':errors',
        'code' => ':code',
        'status_code' => ':status_code',
        'debug' => ':debug',
]

How can I set the code? I have not found the method.

Thank you very much.

imageslr commented 6 years ago

OK I see that I can use $this->respones->errorResponse(403, 'xxx', 1100). 😃 But it do costs me a lot of time to figure it out... Not find any docs online.