0.2.0 • Published 7 years ago

django-exceptions v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Handle and parse Django REST Framework validation messages with aplomb.

npm i django-exceptions --save

Travis   Coveralls   npm   License MIT

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.

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 you might do something like the following to render the messages:

import parse from 'django-exceptions';

render() {
    
    return (
        <ul className="messages">

            {parse(this.props.messages).map(x => (
                <li>{x.field.join(' → ')}: {x.messages.join(', ')}</li>
            ))}

        </ul>
    );

}
0.2.0

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago