wemake-services / wemake-django-rest

Create Django REST APIs the right way, no magic intended
MIT License
11 stars 1 forks source link

Implement error handling #5

Open sobolevn opened 5 years ago

sobolevn commented 5 years ago

I have troubles in creating a declarative error handling. But, thanks to hanami authors that there's a nice concept in their framework: https://guides.hanamirb.org/actions/exception-handling/

So, how should this be solved?

class UserListMethod(BodylessMethod):
      exceptions = {
            TypeError: Error(status=403, message='User is an alien!'),
            AttributeError: 403,
            SomeCustomError: callable,  # type: Callable[[request, request_payload, exception], Error]
      }

     ...