|
43 | 43 | |
|
44 | 44 | | ApiCode::SOMETHING => 'api.something',
|
45 | 45 | |
|
46 |
| - | See README if you want to provide own messages for built-in codes too. |
| 46 | + | See docs/exceptions.md if you want to provide own messages for built-in codes too. |
47 | 47 | |
|
48 | 48 | */
|
49 | 49 | 'map' => [
|
|
106 | 106 | 'encoding_options' => JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE,
|
107 | 107 |
|
108 | 108 |
|
| 109 | + /* |
| 110 | + |-------------------------------------------------------------------------- |
| 111 | + | Response JSON keys mapping |
| 112 | + |-------------------------------------------------------------------------- |
| 113 | + | |
| 114 | + | You can remap response JSON keys if really needed. |
| 115 | + | |
| 116 | + | |
| 117 | + | WARNING: there's NO duplicate check at runtime, so if you remap two keys |
| 118 | + | to the same values you will end up with problems. There's testing trait |
| 119 | + | to prevent this from happening, so ensure you unit test your app (see docs!) |
| 120 | + | |
| 121 | + | NOTE: Ensure you have this config file using: |
| 122 | + | |
| 123 | + | use MarcinOrlowski\ResponseBuilder\ResponseBuilder; |
| 124 | + | |
| 125 | + | if you want to use custom mapping. |
| 126 | + | |
| 127 | + | It's safe to completely remove/comment out this config element. |
| 128 | + | |
| 129 | + */ |
| 130 | +// 'response_key_map' => [ |
| 131 | +// ResponseBuilder::KEY_SUCCESS => 'success', |
| 132 | +// ResponseBuilder::KEY_CODE => 'code', |
| 133 | +// ResponseBuilder::KEY_LOCALE => 'locale', |
| 134 | +// ResponseBuilder::KEY_MESSAGE => 'message', |
| 135 | +// ResponseBuilder::KEY_DATA => 'data', |
| 136 | +// ], |
| 137 | + |
109 | 138 | /*
|
110 | 139 | |--------------------------------------------------------------------------
|
111 | 140 | | Exception handler error codes
|
|
119 | 148 | */
|
120 | 149 | 'exception_handler' => [
|
121 | 150 |
|
122 |
| - // By default, exception provided messages have higher priority than mapped error messages. |
123 |
| - // This behaviour can be configured with `use_exception_message_first` option. When option |
| 151 | + // By default, exception provided messages has higher priority than mapped error messages. |
| 152 | + // This behaviour can be configured with `use_exception_message_first` option. When it |
124 | 153 | // is set to `true` (which is default value) and when exception's `getMessage()` returns non empty
|
125 |
| - // string, that string will be used as returned as `message` w/o further processing. If |
| 154 | + // string, that string will be used and returned as `message` w/o further processing. If |
126 | 155 | // it is set to `true` but exception provides no message, then mapped message will be used
|
127 | 156 | // and the ":message" placeholder will be substituted with exception class name. When option
|
128 |
| - // is set to @false, then pre 2.0 behaviour takes place and mapped messages will always be used |
129 |
| - // with `:message` placeholder being substituted with exception message (can if it is empty string). |
| 157 | + // is set to @false, then mapped messages will always be used with `:message` placeholder |
| 158 | + // being substituted with exception message (can if it is empty string). |
130 | 159 | 'use_exception_message_first' => env('EX_USE_EXCEPTION_MESSAGE', true),
|
131 | 160 |
|
132 | 161 |
|
133 | 162 | // Map exception to your own error codes. That way, when cascading
|
134 | 163 | // you will still know which module thrown this exception
|
135 | 164 | 'exception' => [
|
| 165 | + |
136 | 166 | // 'http_not_found' => [
|
137 |
| -// 'code' => \App\ApiCode::HTTP_NOT_FOUND, |
| 167 | +// 'code' => \App\ApiCodes::HTTP_NOT_FOUND, |
138 | 168 | // 'http_code' => Symfony\Component\HttpFoundation\Response\::HTTP_BAD_REQUEST,
|
139 | 169 | // ],
|
140 | 170 | // 'http_service_unavailable' => [
|
141 |
| -// 'code' => \App\ApiCode::HTTP_SERVICE_UNAVAILABLE, |
| 171 | +// 'code' => \App\ApiCodes::HTTP_SERVICE_UNAVAILABLE, |
142 | 172 | // 'http_code' => Symfony\Component\HttpFoundation\Response\::HTTP_BAD_REQUEST,
|
143 | 173 | // ],
|
144 | 174 | // 'http_exception' => [
|
145 |
| -// 'code' => \App\ApiCode::HTTP_EXCEPTION, |
| 175 | +// 'code' => \App\ApiCodes::HTTP_EXCEPTION, |
146 | 176 | // 'http_code' => Symfony\Component\HttpFoundation\Response\::HTTP_BAD_REQUEST,
|
147 | 177 | // ],
|
148 | 178 | // 'uncaught_exception' => [
|
149 |
| -// 'code' => \App\ApiCode::UNCAUGHT_EXCEPTION, |
| 179 | +// 'code' => \App\ApiCodes::UNCAUGHT_EXCEPTION, |
150 | 180 | // 'http_code' => Symfony\Component\HttpFoundation\Response\::HTTP_INTERNAL_SERVER_ERROR,
|
151 | 181 | // ],
|
| 182 | +// 'authentication_exception' => [ |
| 183 | +// 'code' => \App\ApiCodes::AUTHENTICATION_EXCEPTION, |
| 184 | +// 'http_code' => Symfony\Component\HttpFoundation\Response\::HTTP_UNAUTHORIZED, |
| 185 | +// ], |
| 186 | +// 'validation_exception' => [ |
| 187 | +// 'code' => \App\ApiCodes::VALIDATION_EXCEPTION, |
| 188 | +// 'http_code' => Symfony\Component\HttpFoundation\Response\::HTTP_UNPROCESSABLE_ENTITY, |
| 189 | +// ], |
| 190 | + |
152 | 191 | ],
|
153 | 192 |
|
154 | 193 | ],
|
|
162 | 201 | */
|
163 | 202 |
|
164 | 203 | 'debug' => [
|
| 204 | +// 'debug_key' => 'debug', |
| 205 | + |
165 | 206 | 'exception_handler' => [
|
166 | 207 | /**
|
167 |
| - * When ExceptionHandler kicks in and this is set to @true (default), |
168 |
| - * then **if** your `app.debug` is `true` too, returned JSON structure |
169 |
| - * will contain `debug` node with additional exception base trace (class |
170 |
| - * name, file name, line number). If `app.debug` is anything but @true, |
171 |
| - * no debug info is added. |
| 208 | + * Name of the JSON key trace data should be put under in `debug` node. |
| 209 | + */ |
| 210 | +// 'trace_key' => 'trace', |
| 211 | + |
| 212 | + /** |
| 213 | + * When ExceptionHandler kicks in and this is set to @true, |
| 214 | + * then returned JSON structure will contain additional debug data |
| 215 | + * with information about class name, file name and line number. |
172 | 216 | */
|
173 |
| - 'trace_enabled' => true, |
| 217 | + 'trace_enabled' => env('APP_DEBUG', false), |
174 | 218 | ],
|
175 | 219 | ],
|
176 | 220 |
|
|
0 commit comments