https://github.com/wildhoney/djangoexceptions
Handle and parse Django REST Framework validation messages with aplomb.
https://github.com/wildhoney/djangoexceptions
api django error errors framework message messages rest validation validator validators
Last synced: about 1 year ago
JSON representation
Handle and parse Django REST Framework validation messages with aplomb.
- Host: GitHub
- URL: https://github.com/wildhoney/djangoexceptions
- Owner: Wildhoney
- License: mit
- Created: 2017-06-17T17:04:38.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-12T16:31:47.000Z (over 8 years ago)
- Last Synced: 2025-03-04T19:37:10.759Z (about 1 year ago)
- Topics: api, django, error, errors, framework, message, messages, rest, validation, validator, validators
- Language: JavaScript
- Homepage:
- Size: 162 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

> Handle and parse [Django REST Framework validation messages](https://docs.djangoproject.com/en/1.11/ref/forms/validation/) with aplomb.
`npm i django-exceptions --save`




# Getting Started
Django Exceptions will attempt to flatten the validation messages into a single hierarchy, as otherwise the validation messages are infinitely nested, which makes it troublesome to render to HTML. Thus you are guanrateed to have a single array of all validation messages, with a `field` and `messages` key – both of which themselves are arrays.
```javascript
import parse from 'django-exceptions';
const data = await fromApi();
parse(data).forEach(x => {
console.log('Field:', x.field);
console.log('Messages:', x.messages);
});
```
In [React](https://github.com/facebook/react) you *might* do something like the following to render the messages:
```javascript
import parse from 'django-exceptions';
render() {
return (
- {x.field.join(' → ')}: {x.messages.join(', ')}
{parse(this.props.messages).map(x => (
))}
);
}
```