diff options
Diffstat (limited to 'python-hipo-drf-exceptions.spec')
| -rw-r--r-- | python-hipo-drf-exceptions.spec | 500 |
1 files changed, 500 insertions, 0 deletions
diff --git a/python-hipo-drf-exceptions.spec b/python-hipo-drf-exceptions.spec new file mode 100644 index 0000000..893ced5 --- /dev/null +++ b/python-hipo-drf-exceptions.spec @@ -0,0 +1,500 @@ +%global _empty_manifest_terminate_build 0 +Name: python-hipo-drf-exceptions +Version: 0.1.8 +Release: 1 +Summary: A Django app for returning consistent, verbose and easy to parse error messages on Django Rest Framework backends. +License: Apache-2.0 +URL: https://github.com/hipo/hipo-drf-exceptions +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/f8/58/c1ef6c4433370772b5a0b1029e0b6fc37ec158b8091f0aa0aa1c30861615/hipo-drf-exceptions-0.1.8.tar.gz +BuildArch: noarch + +Requires: python3-Django +Requires: python3-djangorestframework + +%description +# Hipo DRF Exceptions +[](https://hipolabs.com) [](https://travis-ci.org/Hipo/hipo-drf-exceptions) [](https://pypi.org/project/hipo-drf-exceptions/) + +A [Django](https://www.djangoproject.com) app for returning consistent, verbose and easy to parse error messages on [Django Rest Framework](https://www.django-rest-framework.org/) backends. + +Parsing error messages generated by DRF is a bit of pain for client developers. They need to try-catch different possible error formats. When you add errors raised at the business logic level, the error parsing becomes even more difficult. + +This package unifies the output format of DRF in the "Hipo Error Protocol". + +*No more "An error occured." errors.* + +This package also provides the "fallback message", a text string that always contains a human readable error summary. This way, client developers can always fallback and show this message when the client receives an error that is not handled. + +> Sounds cool! Can client devs just use this field all the time? + +In our past experience, we noticed that some _lazy_ client developers tend to use this message and avoid writing any code to parse the error bundle. However, the message in this field is automatically generated and may not always be suitable for end users. In order to make clear that this is a *fallback* message, we named this field "fallback_message" + + +## Table of Contents + +- [Installation](#installation) +- [Usage](#usage) +- [Client SDKs](#client-sdks) +- [Support](#support) +- [Contributing](#contributing) + +## Installation + +You can get stable version of Hipo Excepitons by using pip, pipenv or poetry: +``` +pip install hipo-drf-exceptions +``` + +## Usage + +### Handler +You will need to set `EXCEPTION_HANDLER` of the `REST_FRAMEWORK` setting of your Django project settings.py file. +``` +REST_FRAMEWORK = { + .. + 'EXCEPTION_HANDLER': 'hipo_drf_exceptions.handler', +} +``` + +### Example Error Responses + +#### Field Error + +You can make validations on model level and raise `ValidationError` when it is required. +```python +from django.core.exceptions import ValidationError + +class Invitation(models.Model): + email = models.EmailField(unique=True) + + def save(self, *args, **kwargs): + if User.objects.filter(email=self.email).exists(): + raise ValidationError({"email": _("Email is already registered.")}) + + super().save(*args, **kwargs) +``` + +If the view or serializer encounters with the `ValidationError`, The response will be like: +```json +{ + "type": "ValidationError", + "detail": { + "email": [ + "Email is already registered." + ] + }, + "fallback_message": "Email is already registered." +} +``` + +#### Non Field Error +Implement your own error classes. +```python +from hipo_drf_exceptions import BaseAPIException + +class ProfileCredentialError(BaseAPIException): + default_detail = _('Profile credentials are not correct.') +``` + +Raise error when it is required. +```python +class AuthenticationView(GenericAPIView): + + def post(self, request, *args, **kwargs): + .. + if not profile.check_password(password): + raise ProfileCredentialError() + .. +``` + +The response will be like: +```json +{ + "type": "ProfileCredentialError", + "detail": { + "non_field_errors": [ + "Profile credentials are not correct." + ] + }, + "fallback_message": "Profile credentials are not correct." +} +``` + +## Settings +You can set default key for Django's non field errors key (it is `"__all__"`) by adding this to your Django settings: + +``` +HIPO_DRF_EXCEPTIONS_SETTINGS = { + "DJANGO_NON_FIELD_ERRORS_KEY": "field_free_errors" # by default it's "non_field_errors" to be consistent with DRF. +} +``` + +## Testing +Install dependencies via poetry. +``` +poetry install +``` + +Run tests. +``` +pytest test_project +``` + +## Client SDKs + +We have SDKs for client side. + +- [`hipo-exceptions-js`](https://github.com/Hipo/hipo-exceptions-js) is for JS. +- [`hipo-exceptions-android`](https://github.com/Hipo/hipo-exceptions-android) is for Android. + +## Support + +Please [open an issue](https://github.com/hipo/hipo-drf-exceptions/issues/new) for support. + +## Contributing + +Please contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch, add commits, and [open a pull request](https://github.com/hipo/hipo-drf-exceptions/compare/). + + +%package -n python3-hipo-drf-exceptions +Summary: A Django app for returning consistent, verbose and easy to parse error messages on Django Rest Framework backends. +Provides: python-hipo-drf-exceptions +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-hipo-drf-exceptions +# Hipo DRF Exceptions +[](https://hipolabs.com) [](https://travis-ci.org/Hipo/hipo-drf-exceptions) [](https://pypi.org/project/hipo-drf-exceptions/) + +A [Django](https://www.djangoproject.com) app for returning consistent, verbose and easy to parse error messages on [Django Rest Framework](https://www.django-rest-framework.org/) backends. + +Parsing error messages generated by DRF is a bit of pain for client developers. They need to try-catch different possible error formats. When you add errors raised at the business logic level, the error parsing becomes even more difficult. + +This package unifies the output format of DRF in the "Hipo Error Protocol". + +*No more "An error occured." errors.* + +This package also provides the "fallback message", a text string that always contains a human readable error summary. This way, client developers can always fallback and show this message when the client receives an error that is not handled. + +> Sounds cool! Can client devs just use this field all the time? + +In our past experience, we noticed that some _lazy_ client developers tend to use this message and avoid writing any code to parse the error bundle. However, the message in this field is automatically generated and may not always be suitable for end users. In order to make clear that this is a *fallback* message, we named this field "fallback_message" + + +## Table of Contents + +- [Installation](#installation) +- [Usage](#usage) +- [Client SDKs](#client-sdks) +- [Support](#support) +- [Contributing](#contributing) + +## Installation + +You can get stable version of Hipo Excepitons by using pip, pipenv or poetry: +``` +pip install hipo-drf-exceptions +``` + +## Usage + +### Handler +You will need to set `EXCEPTION_HANDLER` of the `REST_FRAMEWORK` setting of your Django project settings.py file. +``` +REST_FRAMEWORK = { + .. + 'EXCEPTION_HANDLER': 'hipo_drf_exceptions.handler', +} +``` + +### Example Error Responses + +#### Field Error + +You can make validations on model level and raise `ValidationError` when it is required. +```python +from django.core.exceptions import ValidationError + +class Invitation(models.Model): + email = models.EmailField(unique=True) + + def save(self, *args, **kwargs): + if User.objects.filter(email=self.email).exists(): + raise ValidationError({"email": _("Email is already registered.")}) + + super().save(*args, **kwargs) +``` + +If the view or serializer encounters with the `ValidationError`, The response will be like: +```json +{ + "type": "ValidationError", + "detail": { + "email": [ + "Email is already registered." + ] + }, + "fallback_message": "Email is already registered." +} +``` + +#### Non Field Error +Implement your own error classes. +```python +from hipo_drf_exceptions import BaseAPIException + +class ProfileCredentialError(BaseAPIException): + default_detail = _('Profile credentials are not correct.') +``` + +Raise error when it is required. +```python +class AuthenticationView(GenericAPIView): + + def post(self, request, *args, **kwargs): + .. + if not profile.check_password(password): + raise ProfileCredentialError() + .. +``` + +The response will be like: +```json +{ + "type": "ProfileCredentialError", + "detail": { + "non_field_errors": [ + "Profile credentials are not correct." + ] + }, + "fallback_message": "Profile credentials are not correct." +} +``` + +## Settings +You can set default key for Django's non field errors key (it is `"__all__"`) by adding this to your Django settings: + +``` +HIPO_DRF_EXCEPTIONS_SETTINGS = { + "DJANGO_NON_FIELD_ERRORS_KEY": "field_free_errors" # by default it's "non_field_errors" to be consistent with DRF. +} +``` + +## Testing +Install dependencies via poetry. +``` +poetry install +``` + +Run tests. +``` +pytest test_project +``` + +## Client SDKs + +We have SDKs for client side. + +- [`hipo-exceptions-js`](https://github.com/Hipo/hipo-exceptions-js) is for JS. +- [`hipo-exceptions-android`](https://github.com/Hipo/hipo-exceptions-android) is for Android. + +## Support + +Please [open an issue](https://github.com/hipo/hipo-drf-exceptions/issues/new) for support. + +## Contributing + +Please contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch, add commits, and [open a pull request](https://github.com/hipo/hipo-drf-exceptions/compare/). + + +%package help +Summary: Development documents and examples for hipo-drf-exceptions +Provides: python3-hipo-drf-exceptions-doc +%description help +# Hipo DRF Exceptions +[](https://hipolabs.com) [](https://travis-ci.org/Hipo/hipo-drf-exceptions) [](https://pypi.org/project/hipo-drf-exceptions/) + +A [Django](https://www.djangoproject.com) app for returning consistent, verbose and easy to parse error messages on [Django Rest Framework](https://www.django-rest-framework.org/) backends. + +Parsing error messages generated by DRF is a bit of pain for client developers. They need to try-catch different possible error formats. When you add errors raised at the business logic level, the error parsing becomes even more difficult. + +This package unifies the output format of DRF in the "Hipo Error Protocol". + +*No more "An error occured." errors.* + +This package also provides the "fallback message", a text string that always contains a human readable error summary. This way, client developers can always fallback and show this message when the client receives an error that is not handled. + +> Sounds cool! Can client devs just use this field all the time? + +In our past experience, we noticed that some _lazy_ client developers tend to use this message and avoid writing any code to parse the error bundle. However, the message in this field is automatically generated and may not always be suitable for end users. In order to make clear that this is a *fallback* message, we named this field "fallback_message" + + +## Table of Contents + +- [Installation](#installation) +- [Usage](#usage) +- [Client SDKs](#client-sdks) +- [Support](#support) +- [Contributing](#contributing) + +## Installation + +You can get stable version of Hipo Excepitons by using pip, pipenv or poetry: +``` +pip install hipo-drf-exceptions +``` + +## Usage + +### Handler +You will need to set `EXCEPTION_HANDLER` of the `REST_FRAMEWORK` setting of your Django project settings.py file. +``` +REST_FRAMEWORK = { + .. + 'EXCEPTION_HANDLER': 'hipo_drf_exceptions.handler', +} +``` + +### Example Error Responses + +#### Field Error + +You can make validations on model level and raise `ValidationError` when it is required. +```python +from django.core.exceptions import ValidationError + +class Invitation(models.Model): + email = models.EmailField(unique=True) + + def save(self, *args, **kwargs): + if User.objects.filter(email=self.email).exists(): + raise ValidationError({"email": _("Email is already registered.")}) + + super().save(*args, **kwargs) +``` + +If the view or serializer encounters with the `ValidationError`, The response will be like: +```json +{ + "type": "ValidationError", + "detail": { + "email": [ + "Email is already registered." + ] + }, + "fallback_message": "Email is already registered." +} +``` + +#### Non Field Error +Implement your own error classes. +```python +from hipo_drf_exceptions import BaseAPIException + +class ProfileCredentialError(BaseAPIException): + default_detail = _('Profile credentials are not correct.') +``` + +Raise error when it is required. +```python +class AuthenticationView(GenericAPIView): + + def post(self, request, *args, **kwargs): + .. + if not profile.check_password(password): + raise ProfileCredentialError() + .. +``` + +The response will be like: +```json +{ + "type": "ProfileCredentialError", + "detail": { + "non_field_errors": [ + "Profile credentials are not correct." + ] + }, + "fallback_message": "Profile credentials are not correct." +} +``` + +## Settings +You can set default key for Django's non field errors key (it is `"__all__"`) by adding this to your Django settings: + +``` +HIPO_DRF_EXCEPTIONS_SETTINGS = { + "DJANGO_NON_FIELD_ERRORS_KEY": "field_free_errors" # by default it's "non_field_errors" to be consistent with DRF. +} +``` + +## Testing +Install dependencies via poetry. +``` +poetry install +``` + +Run tests. +``` +pytest test_project +``` + +## Client SDKs + +We have SDKs for client side. + +- [`hipo-exceptions-js`](https://github.com/Hipo/hipo-exceptions-js) is for JS. +- [`hipo-exceptions-android`](https://github.com/Hipo/hipo-exceptions-android) is for Android. + +## Support + +Please [open an issue](https://github.com/hipo/hipo-drf-exceptions/issues/new) for support. + +## Contributing + +Please contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch, add commits, and [open a pull request](https://github.com/hipo/hipo-drf-exceptions/compare/). + + +%prep +%autosetup -n hipo-drf-exceptions-0.1.8 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-hipo-drf-exceptions -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Mon May 15 2023 Python_Bot <Python_Bot@openeuler.org> - 0.1.8-1 +- Package Spec generated |
