Given a Django ValidationError, return a list of ErrorDetail, with the `code` populated.
(exc_info)
| 211 | |
| 212 | |
| 213 | def get_error_detail(exc_info): |
| 214 | """ |
| 215 | Given a Django ValidationError, return a list of ErrorDetail, |
| 216 | with the `code` populated. |
| 217 | """ |
| 218 | code = getattr(exc_info, 'code', None) or 'invalid' |
| 219 | |
| 220 | try: |
| 221 | error_dict = exc_info.error_dict |
| 222 | except AttributeError: |
| 223 | return [ |
| 224 | ErrorDetail((error.message % error.params) if error.params else error.message, |
| 225 | code=error.code if error.code else code) |
| 226 | for error in exc_info.error_list] |
| 227 | return { |
| 228 | k: [ |
| 229 | ErrorDetail((error.message % error.params) if error.params else error.message, |
| 230 | code=error.code if error.code else code) |
| 231 | for error in errors |
| 232 | ] for k, errors in error_dict.items() |
| 233 | } |
| 234 | |
| 235 | |
| 236 | class CreateOnlyDefault: |
no test coverage detected